繁体   English   中英

在多域Varnish上重定向HTTPS

[英]Redirect HTTPS on multidomain Varnish

我有两个基于相同框架(magento2)的域domain1.it domain2.com

我想将它们重定向到各自的SSL版本。 https://domain1.it https://domain2.com

域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);
}

问题是合成器总是重定向到相同的域。

我应该添加一个if条件,在这里我可以调用子例程,该子例程重定向到domain2的https

为了热爱一切美好的事物,请停止使用超凡脱俗的状态代码,301和302完美无瑕,更加清晰,节省了您的电话。

我建议不要使用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);
    }
}

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

Bitnami工程师在这里。 我刚刚查看了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);
    }
}

当您要将客户端重定向到站点的SSL版本时,这很有用。 更多信息在这里:

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

暂无
暂无

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

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