【问题标题】:Nginx reverse proxy to an https address behind corporate proxyNginx 反向代理到公司代理后面的 https 地址
【发布时间】:2021-08-16 07:40:34
【问题描述】:

我正在尝试将 Nginx 反向代理设置为 AWS API 网关地址,例如公司代理后面的 https://12345.execute-api.eu-central-1.amazonaws.com/v2

我尝试对www.example.com 进行以下设置,它可以工作。但是,一旦我像https://www.example.com 一样将https 添加到它,它就会失败。我添加了 https,因为没有它就无法访问我的 API 网关地址。

当前工作配置:

server {
    listen 80;
    listen [::]:80;
    listen 443;
    underscores_in_headers on;
   
    location / {
        proxy_pass_request_headers      on;
        proxy_set_header Host www.example.com;
        proxy_pass  http://myCorporateProxy.org:8080;
    }
}

我想要实现的目标和错误: 将所有传入流量重定向到 localhost 以重定向到类似于 https://123456.execute-api.region.amazonaws.com/v2/ 的 API 网关地址 尝试以下配置时,我收到 302 临时移动错误。 在配置中它看起来像这样:

server {
    listen 80;
    listen [::]:80;
    listen 443;
    underscores_in_headers on;
   
    location / {
        proxy_pass_request_headers      on;
        proxy_set_header Host https://www.example.com;
        proxy_pass  http://myCorporateProxy.org:8080;
    }
}

【问题讨论】:

    标签: nginx nginx-reverse-proxy nginx-config


    【解决方案1】:

    你应该尝试这样的事情。从 http 重定向到 https 有点不同。

    server {
        listen 80;
        server_name myCorporateProxy.org www.myCorporateProxy.org;
        return 301 https://myCorporateProxy.org$request_uri;
    }
    

    【讨论】:

    • 我用各种设置尝试了这个解决方案,如下所示,它们都不起作用。我基本上通过将端口号移动到不同的地方来尝试相同的设置。我也尝试过使用和不使用 location / { ... } 部分。
    猜你喜欢
    • 2019-03-24
    • 1970-01-01
    • 1970-01-01
    • 2012-08-05
    • 1970-01-01
    • 2015-09-11
    • 2021-04-06
    • 2015-01-04
    • 2017-08-25
    相关资源
    最近更新 更多