簡體   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