Search code examples
ruby-on-railssslnginxpassengerruby-on-rails-2

Too Many Redirects: passenger+nginx SSLRequirement


I have an old rails 2.3 app that I'm in the process of moving to nginx+Passenger (from Apache+Passenger). Nginx is configured for SSL and appears to be functioning correctly, except I am getting getting stuck in a 302 redirect loop from my Rails app.

The rails app thinks that the requests are not ssl (request.ssl? must be evaluating to false). In the production.log, each log entry shows the request as http. If I disable the SSLRequirement plugin, then the redirect loop goes away. However, I'd like to make sure my rails app is detecting an https request so that it can set the protocol correctly when I create absolute URLs.

The only reason I mention the previous Apache+Passenger setup is that the SSLRequirement plugin was functioning properly under that configuration.

The nginx config for my virtual host looks like this:

server {
  listen       443 ssl;
  server_name  new.example.com;
  root /home/user/railsapps/example-setup/public;
  passenger_enabled on;
  ssl_certificate /etc/nginx/ssl/2013/example.com.chained.crt;
  ssl_certificate_key /etc/nginx/ssl/2013/example.key;
  ssl_protocols       SSLv3 TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers         HIGH:!aNULL:!MD5;
}

Solution

  • The answer was found here:

    Error 310. Too many redirects with nginx + rails 3

    I simply needed to change the config to the following:

    server {
      listen 443;
      ssl on;
      server_name  new.usfamilytree.com;
      root /home/admin/railsapps/example-setup/public;
      passenger_enabled on;
      ssl_certificate /etc/nginx/ssl/2013/example.com.chained.crt;
      ssl_certificate_key /etc/nginx/ssl/2013/example.key;
      ssl_protocols       SSLv3 TLSv1 TLSv1.1 TLSv1.2;
      ssl_ciphers         HIGH:!aNULL:!MD5;
    }
    

    I removed the ssl off of the listen line and added the "ssl on;" line.