Назад | Перейти на главную страницу

nginx вызывает цикл перенаправления в случае запроса https

Недавно я перенес свое приложение rails с HTTP-запроса на HTTPS.

URL моего приложения выглядит следующим образом: https://testmate.persistent.co.in

У меня есть режим всех необходимых конфигураций в файле nginx.conf

Мой файл 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;
    }
}


}

Если я получу доступ к указанному выше URL внутри интрасети все работает нормально.

Но всякий раз, когда я пытаюсь получить к нему доступ извне сети, это вызывает бесконечный цикл запроса перенаправления.

Он отлично работает, если я полностью удалю серверный блок для порта 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;

Может помочь, решите мне подобную проблему один раз.