ELB nginx – redirect循环

我有nodejs应用程序(在本地工作正常)后面的nginx与以下configuration:

00_elastic_beanstalk_proxy.conf

upstream nodejs { server 127.0.0.1:8081; keepalive 256; } server { listen 8080; return 301 https://$host$request_uri; location / { proxy_pass http://nodejs; proxy_set_header Connection ""; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } gzip on; gzip_comp_level 4; gzip_types text/html text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascrip$ } 

https.conf

 server { listen 443; server_name localhost; ssl on; ssl_certificate /etc/pki/tls/certs/server.crt; ssl_certificate_key /etc/pki/tls/certs/server.key; ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; ssl_prefer_server_ciphers on; location / { proxy_pass http://nodejs; proxy_set_header Connection ""; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } 

我在一个人之后把它拿过来,不确定哪一部分是由amazon ELB生成的。

nginx和Node应用程序都启动了,我得到了: __url__redirect了太多次。

负载平衡器通过HTTP转发请求,这是创buildredirect循环。

我已经通过在我的redirect周围添加$ http_x_forwarded_proto标头的检查来修复它:

 if ($http_x_forwarded_proto != "https") { return 301 https://$host$request_uri; }