我在 nginx 后面有一个 nodejs 应用程序(在本地运行良好),其配置如下:
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配置文件
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;
}
}
我接手了某人的工作,但不确定哪部分是由亚马逊 ELB 生成的。
nginx 和 node 应用程序都已启动,我得到了: __url__ 将您重定向过多次。
答案1
负载均衡器正在通过 HTTP 转发请求,从而创建重定向循环。
我通过在重定向周围添加对 $http_x_forwarded_proto 标头的检查来修复此问题:
if ($http_x_forwarded_proto != "https") {
return 301 https://$host$request_uri;
}