我正在从我的设置
nginx > apache/php
至
haproxy > nginx > apache/php
(使用haproxy 1.5-dev18,在ssl支持下编译)
nginx和haproxy都正确设置了HTTP_X_FORWARDED_PROTO头。 但是,当nginx从haproxy获取sslstream量时,它将连接视为http并将标头设置为如此。
我如何设置nginx转发HTTP_X_FORWARDED_PROTO头,如果它存在,但否则继续基于连接设置它?
我想出了如何解决这个问题。 问题是,在我的configuration的这一行上,nginx覆盖了haproxy设置的头文件:
proxy_set_header X-Forwarded-Proto $scheme;
我修正了这个问题:
map $http_x_forwarded_proto $thescheme { default $scheme; https https; }
并更改proxy_set_header行以使用新的scheme:
proxy_set_header X-Forwarded-Proto $thescheme;
我不能只是发表评论,所以我发布这个答案:你能给我们一部分或全部你的nginxconfiguration,所以我们可以看到它有什么问题吗? 可能你的HAProxyconfiguration呢?
我能想到的第一个问题是你的HAProxy正在做SSL终止。 总结一下,为了卸载后端服务器,可以configuration一个负载平衡器来完成所有的ssl事情,然后用HTTP与后端服务器进行通信。 像这里的计划: http : //blog.exceliance.fr/2012/09/10/how-to-get-ssl-with-haproxy-getting-rid-of-stunnel-stud-nginx-or-pound/
为了给你一个很好的回答你的问题,你能检查你的http <> httpsconfiguration没有任何回环问题吗? 也许你可以redirecthttp到http,https到https,然后强制http被redirect到https。
你能否检查你是否已经在你的HAProxyconfiguration中启用了ssl passthrough?
另一个解决scheme可能是使用地图,如下所述: http : //redant.com.au/blog/manage-ssl-redirection-in-nginx-using-maps-and-save-the-universe/但它不完全我想你想达到什么,不是?
我有与AWS ELB相同的需求
这是我的解决scheme:
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;