NGINX:执行反向代理时,如何删除端口?

时间:2019-05-28 22:33:29

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

我设置了一个Nginx反向代理,该代理被用作多个服务器(例如融合)的SSL卸载。我已经成功使用http://confluencehttps://confluence,但是当我尝试重定向http://confluence:8090时,它尝试转到https://confluence:8090并失败。

如何从URL中删除端口?

下面的配置有些修饰,但可能有帮助吗?标头中的$ server_port位是否引起了问题?

server {
    listen      8090;
    server_name confluence;

    return 301 https://confluence$request_uri;
}

server {
    listen      443 ssl http2;
    server_name confluence;
    location / {
        proxy_http_version 1.1;
        proxy_pass http://confbackend:8091
        proxy_set_header X-Forwarded-Host $http_host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $server_name:$server_port;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Upgrade $http_upgrade; #WebSocket Support
        proxy_set_header Connection $connection_upgrade; #WebSocket Support
   }
}

这里似乎有很多答案涉及http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_redirect,但在那混乱的混乱中我没有安慰。

我还以为您将拥有一台服务器,但是我正在尝试https://serverfault.com/questions/815797/nginx-rewrite-to-new-protocol-and-port的建议

我尝试弄乱port_in_redirect off;选项,但也许我用错了吗?

1 个答案:

答案 0 :(得分:1)

您的问题是STS标头

add_header Strict-Transport-Security max-age=31536000;

添加STS标头时。对http://example.com:8090的第一个请求会生成一个对https://example.com的重定向

https://example.com然后在响应中返回STS标头,并且浏览器会记住example.com始终需要在https上投放,无论如何。端口没有任何作用

现在,当您再次向http://example.com:8090发出请求时,STS将启动,然后将其转换为https://example.com:8090,这是您的问题

因为端口只能服务httphttps,所以不能使用8090http重定向到https并重定向{{1} } https8090 https

相关问题