代码之家  ›  专栏  ›  技术社区  ›  tavier

我可以在nginx上游使用http和https吗

  •  0
  • tavier  · 技术社区  · 5 年前

    我有如下Nginx配置:

    upstream staging {
        server myappstaging.somedomain.com;
    }
    
    upstream prod {
        server myapp.somedomain.com:443;
    }
    
    # map to different upstream backends based on header
    map $http_x_server_select $pool {
        default "prod";
        staging "staging";
    }
    
    server {
        listen 80;
        server_name myapp.mydomain.com;
    
        location / {
            proxy_pass https://$pool;
        }
    }
    

    我想把请求转发给 x-server-select http://myappstaging.somedomain.com 为了刺激 https://myapp.somedomain.com:443

    Nginx有可能做到这一点吗?

    0 回复  |  直到 5 年前
        1
  •  2
  •   Richard Smith    5 年前

    将方案作为变量的一部分。

    例如:

    map $http_x_server_select $pool {
        default "https://prod";
        staging "http://staging";
    }
    

    proxy_pass $pool;