我有一些关于nginx与http和https绕过的问题,在上游块
上游区块:
upstream bypass{
server 192.168.99.1:80; #http
server 192.168.99.2:443 backup; #https
}
当http 80出现问题(服务器关闭等)时,我想重定向到https 443,
这个块对我不起作用。
位置块:
location / {
proxy_pass https://bypass;
proxy_redirect off;
}
我该如何解决这个问题?
在黑暗中拍摄。假设您在上游混合使用HTTP和HTTPS时出现问题,可以在location
块中尝试:
location {
try_files @bypass-http @bypass-https =404;
location @bypass-http {
proxy_pass http://bypass;
proxy_redirect off;
}
location @bypass-https {
proxy_pass https://bypass;
proxy_redirect off;
}
}
如果这不起作用,将bypass
上游块拆分为bypass1
和bypass2
,并在相应的位置块中相应地引用它们:
upstream bypass1{
server 192.168.99.1:80; #http
}
upstream bypass2{
server 192.168.99.2:443; #https
}
location {
try_files @bypass-http @bypass-https =404;
location @bypass-http {
proxy_pass http://bypass1;
proxy_redirect off;
}
location @bypass-https {
proxy_pass https://bypass2;
proxy_redirect off;
}
}
第三个选项是在端口80上引用它们,并确保第二个上游服务器将HTTP请求重定向到HTTPS。