我正在尝试设置 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 中的代理路径和位置中添加不同的尾部正斜杠,但没有效果,还添加了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 输出
-$ 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/ /;