我最近将我的rails应用程序从使用HTTP请求迁移到HTTPS。
我的应用程序URL如下所示: https : //testmate.persistent.co.in
我已经在nginx.conf文件中模拟了所有必需的configuration
我的nginx.conf文件如下所示:
# start the http module where we config http access. http { ... server { listen 443; ssl on; ssl_certificate certificate.pem; ssl_certificate_key server.key; ssl_protocols SSLv3; 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_redirect off; proxy_max_temp_file_size 0; proxy_set_header X-Forwarded-Ssl on; # doc root root /var/www/TestMate/current/public/; passenger_enabled on; passenger_use_global_queue on; rails_env production; # vhost specific access log access_log logs/production.access.log main; client_max_body_size 10M; if (-f $document_root/maintenance.html){ rewrite ^(.*)$ /maintenance.html last; break; } location ~* ^.+\.(jpg|jpeg|flv|gif|css|png|js|ico|html|swf|favicon\.ico|robots\.txt)$ { access_log off; expires 365d; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } server { # port to listen on. Can also be set to an IP:PORT listen 80; # sets the domain[s] that this vhost server requests for # doc root root /var/www/TestMate/current/public/; passenger_enabled on; passenger_use_global_queue on; rails_env production; # vhost specific access log access_log logs/production.access.log main; client_max_body_size 10M; if (-f $document_root/maintenance.html){ rewrite ^(.*)$ /maintenance.html last; break; } location ~* ^.+\.(jpg|jpeg|flv|gif|css|png|js|ico|html|swf|favicon\.ico|robots\.txt)$ { access_log off; expires 365d; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
如果我在Intranet中访问上面的URL 一切工作正常 。
但是每当我尝试从外部networking访问它时,都会导致无限循环的redirect请求 。
如果我完全删除端口80的服务器块,它工作正常 。 但是,我的应用程序中有一些不需要HTTPS检查的部分。
在我的nginx production.access.log文件输出进入循环之后:
15/Feb/2012:18:53:02 +05308.301 10.78.0.21 - - 302 "GET / HTTP/1.0" "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.1) Gecko/20100101 Firefox/10.0.1" "http_x_forwarded_for" 100 "-"
以下是我的应用程序production.log文件输出,也进行循环:
Started GET "/" for 66.249.6.106 at 2012-02-15 18:25:28 +0530 Processing by as */* Redirected to https://testmate.persistent.co.in/ Completed 302 Found in 1ms
任何想法为什么发生这种情况?
在下面添加proxy_set_header X-Forwarded-Ssl on;
set $https_enabled on;
这可能有助于为我解决一个类似的问题。