简体   繁体   English

在多域Varnish上重定向HTTPS

[英]Redirect HTTPS on multidomain Varnish

i have got two domain based on same framework (magento2) domain1.it domain2.com 我有两个基于相同框架(magento2)的域domain1.it domain2.com

I would like to redirect them to their respective SSL version. 我想将它们重定向到各自的SSL版本。 https://domain1.it https://domain2.com https://domain1.it https://domain2.com

Domain 1 is correctly configured to redirect to HTTPS and my varnish Config file is: 域1已正确配置为重定向到HTTPS,我的清漆配置文件为:

sub vcl_recv {
if ( (req.http.host ~ "^(?i)www.domain1.it" || req.http.host ~ "^(?i)domain1.it") && req.http.X-Forwarded-Proto !~ "(?i)https") {
return (synth(750, ""));
    }

sub vcl_synth {
if (resp.status == 750) {
    set resp.status = 301;
    set resp.http.Location = "https://domain1.it" + req.url;
return(deliver);
}

the problem is the synth always redirect to the same domain. 问题是合成器总是重定向到相同的域。

I should add an if condition where i could call a subroutines that redirect to https for domain2 我应该添加一个if条件,在这里我可以调用子例程,该子例程重定向到domain2的https

For the love of everything that is good, please stop using otherworldly status codes, 301 and 302 are perfectly fine, clearer and save you a line. 为了热爱一切美好的事物,请停止使用超凡脱俗的状态代码,301和302完美无瑕,更加清晰,节省了您的电话。

I would advise against using x-forwarded-proto and use an SSL/TLS terminator that supports the PROXY protocol, but since this is what you have, here you go: 我建议不要使用x-forwarded-proto并使用支持PROXY协议的SSL / TLS终结器,但是既然这就是您要的,那么您就可以这样做:

sub vcl_recv {
    if (req.http.X-Forwarded-Proto !~ "https") {
        set req.http.location = "https://" + req.http.host + req.url;
        return(synth(301));
    }
}

sub vcl_synth {
    if (resp.status == 301 || resp.status == 302) {
        set resp.http.location = req.http.location;
        return (deliver);
    }
}

relevant link: https://info.varnish-software.com/blog/rewriting-urls-with-varnish-redirection 相关链接: https : //info.varnish-software.com/blog/rewriting-urls-with-varnish-redirection

Bitnami Engineer here. Bitnami工程师在这里。 I just reviewed the Varnish documentation and found this: 我刚刚查看了Varnish文档,发现了这一点:

sub vcl_recv {
    if (client.ip != "127.0.0.1" && std.port(server.ip) == 80 && req.http.host ~ "^(?i)example.com") {
        set req.http.x-redir = "https://" + req.http.host + req.url;
        return(synth(850, "Moved permanently"));
    }
}

sub vcl_synth {
    if (resp.status == 850) {
        set resp.http.Location = req.http.x-redir;
        set resp.status = 302;
        return (deliver);
    }
}

This is useful when you want to redirect the clients to an SSL-version of your site. 当您要将客户端重定向到站点的SSL版本时,这很有用。 More info here: 更多信息在这里:

https://varnish-cache.org/trac/wiki/VCLExampleRedirectInVCL https://varnish-cache.org/trac/wiki/VCLExampleRedirectInVCL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM