nginx proxypath httpsredirect失败,没有结尾斜杠

我试图设置Nginx使用proxy_pass转发请求到几个后端服务。

缺less结尾斜杠的页面上的链接确实在前面有https:// ,但是被redirect到一个带有斜杠的http请求 – 这些连接以拒绝连接结束 – 我只希望通过https访问这些服务。

所以如果一个链接太https://example.com/internal/errorlogs

在浏览器中加载时https://example.com/internal/errorlogs给出Error Code 10061: Connection refused (redirect到http://example.com/internal/errorlogs/

如果我手动追加testing斜杠https://example.com/internal/errorlogs/加载

我已经尝试了不同的尾随正斜杠附加到proxypath和proxy.conf中的位置无效,也添加了server_name_in_redirect off;

这发生在nginx下的多个应用程序,并在Apache反向代理工作

configuration文件;

proxy.conf

 location /internal { proxy_pass http://localhost:8081/internal; include proxy.inc; } .... more entries .... 

/主启用的站点 –

 server { listen 443; server_name example.com; server_name_in_redirect off; include proxy.conf; ssl on; } 

proxy.inc

 proxy_connect_timeout 59s; proxy_send_timeout 600; proxy_read_timeout 600; proxy_buffer_size 64k; proxy_buffers 16 32k; proxy_pass_header Set-Cookie; proxy_redirect off; proxy_hide_header Vary; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; proxy_set_header Accept-Encoding ''; proxy_ignore_headers Cache-Control Expires; proxy_set_header Referer $http_referer; proxy_set_header Host $host; proxy_set_header Cookie $http_cookie; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Ssl on; proxy_set_header X-Forwarded-Proto https; 

curl输出

 -$ curl -I -k https://example.com/internal/errorlogs/ HTTP/1.1 200 OK Server: nginx/1.0.5 Date: Thu, 24 Nov 2011 23:32:07 GMT Content-Type: text/html;charset=utf-8 Connection: keep-alive Content-Length: 14327 -$ curl -I -k https://example.com/internal/errorlogs HTTP/1.1 301 Moved Permanently Server: nginx/1.0.5 Date: Thu, 24 Nov 2011 23:32:11 GMT Content-Type: text/html;charset=utf-8 Connection: keep-alive Content-Length: 127 Location: http://example.com/internal/errorlogs/ 

我看到您添加了server_name_in_redirect指令,但是您需要位置会话上的proxy_redirect指令

http://wiki.nginx.org/HttpProxyModule#proxy_redirect

你会添加这样的东西

 proxy_redirect http://example.com/ /;