所以我已经看过了我可以find的每个示例configuration,但是每次尝试查看需要ssl的页面时,我都会在redirect循环中结束。 我运行nginx / 0.8.53和乘客3.0.2。
这里是sslconfiguration
server { listen 443 default ssl; server_name <redacted>.com www.<redacted>.com; root /home/app/<redacted>/public; passenger_enabled on; rails_env production; ssl_certificate /home/app/ssl/<redacted>.com.pem; ssl_certificate_key /home/app/ssl/<redacted>.key; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X_FORWARDED_PROTO https; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-Url-Scheme $scheme; proxy_redirect off; proxy_max_temp_file_size 0; location /blog { rewrite ^/blog(/.*)?$ http://blog.<redacted>.com/$1 permanent; } location ~* \.(js|css|jpg|jpeg|gif|png)$ { if (-f $request_filename) { expires max; break; } } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }
这里是非sslconfiguration
server { listen 80; server_name <redacted>.com www.<redacted>.com; root /home/app/<redacted>/public; passenger_enabled on; rails_env production; location /blog { rewrite ^/blog(/.*)?$ http://blog.<redacted>.com/$1 permanent; } location ~* \.(js|css|jpg|jpeg|gif|png)$ { if (-f $request_filename) { expires max; break; } } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }
让我知道是否有任何额外的信息,我可以帮助诊断问题。
它看起来像你的应用程序无法检测到它在https上运行,并一次又一次地redirect到https URL。
通常https是基于HTTPS环境variables检测的,nginx的乘客模块允许使用passenger_set_cgi_param指令设置一个。 添加类似的东西
passenger_set_cgi_param HTTPS on;
到https服务器{}块应该帮助。
我认为proxy_set_header指令应该放在位置部分。
尝试使用:
... location / { # needed for SSL proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Url-Scheme $scheme; proxy_max_temp_file_size 0; # Each of those lines may cause an infinate redirect loop #proxy_set_header X-FORWARDED_PROTO https; #proxy_set_header X-Forwarded-Proto $scheme; # This two may break the redirection when on ssl #proxy_set_header Host $http_host; #proxy_redirect off; ...
至less这对我来说很难在nginx之前用haproxy设置环境。
希望这可以帮助你。