我正在嘗試設定 Nginx 使用 proxy_pass 將請求轉發到多個後端服務。
頁面上缺少尾部斜線的連結確實https://
在前面,但會被重定向到帶有尾部斜線的 http 請求 - 最終以連接被拒絕 - 我只希望這些服務可以透過 https 提供。
所以如果連結太https://example.com/internal/errorlogs
在瀏覽器中加載時https://example.com/internal/errorlogs
給出Error Code 10061: Connection refused
(它重定向到http://example.com/internal/errorlogs/
)
https://example.com/internal/errorlogs/
如果我手動附加它加載的試驗斜杠
我嘗試過在 proxy.conf 中的 proxypath 和位置附加各種尾部正斜杠,但沒有效果,還添加了server_name_in_redirect off;
這種情況發生在 nginx 下的多個應用程式上,並且在 apache 反向代理中有效
設定檔;
代理設定檔
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_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 -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/
答案1
我看到您新增了server_name_in_redirect
指令,但您需要proxy_redirect
位置會話上的指令
http://wiki.nginx.org/HttpProxyModule#proxy_redirect
你會添加類似的東西
proxy_redirect http://example.com/ /;