重定向后上游位置更改为 HTTPS
我使用 Nginx 作为反向代理,通过 HTTPS 连接为内部 HTTP 应用程序提供服务。 但我在重定向方面遇到了一些问题。
这是我的设置:
location / {
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://172.16.88.208;
proxy_intercept_errors on;
error_page 302 = @handle_redirects;
}
location @handle_redirects {
resolver 8.8.8.8;
set $orig_loc $upstream_http_location;
proxy_pass $orig_loc;
}
首先,我在没有将解析器设置为 8.8.8.8 的情况下进行了尝试,但遇到了此错误(同时向客户端显示 502):
*1 发送到客户端时没有定义解析器来解析 xxx.xxxx.com,客户端:xxx.xxx.xxx.xxx
设置解析器后,我越来越接近,但还不够。仍然是 502 和这个错误:
*6 连接到上游时 connect() 失败(111:连接被拒绝), 上游:“https://172.16.88.208:443/login”
嗯,这是完全有道理的,因为应用程序托管在 http://,而不是 https://
我在上面的代码中指定了这一点:
设置$orig_loc $upstream_http_location;
为什么 $upstream_http_location 被重定向到 https 页面?
感谢您的任何帮助。
I use Nginx as a reverse proxy to serve an internal HTTP application over a HTTPS connection.
But I hae some problems with redirection.
This is my setup:
location / {
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://172.16.88.208;
proxy_intercept_errors on;
error_page 302 = @handle_redirects;
}
location @handle_redirects {
resolver 8.8.8.8;
set $orig_loc $upstream_http_location;
proxy_pass $orig_loc;
}
At first, I tried it without setting the resolver to 8.8.8.8 but encountered this error (while a 502 was displayed to the client):
*1 no resolver defined to resolve xxx.xxxx.com while sending to client, client: xxx.xxx.xxx.xxx
After setting the resolver I'm getting closer, but not quite. Still a 502 and this error:
*6 connect() failed (111: Connection refused) while connecting to upstream,
upstream: "https://172.16.88.208:443/login"
Well, that makes perfect sense, because the application is hosted at http://, not https://
I specify this in the code above:
set $orig_loc $upstream_http_location;
Why is the $upstream_http_location redirected to a https page?
Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论