Nginx上游有http和https

问题描述 投票:5回答:1

我有一些关于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 ssl nginx https reverse-proxy
1个回答
0
投票

在黑暗中拍摄。假设您在上游混合使用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上游块拆分为bypass1bypass2,并在相应的位置块中相应地引用它们:

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。

© www.soinside.com 2019 - 2024. All rights reserved.