ruby-on-railswebrick

Rails production mode: SSL received a record that exceeded the maximum permissible length


Hi I'm not sure if this is supposed to happen, but when I do a RAILS_ENV=production rails server in my terminal and then try to run localhost:3000 it gives me an error:

Secure Connection Failed

An error occurred during a connection to localhost:3000.

SSL received a record that exceeded the maximum permissible length.

(Error code: ssl_error_rx_record_too_long)

I read somewhere that it might be because my url is https://localhost:3000/ instead of http://localhost:3000/ with the "S" after http? but I can't change it since it keeps going to https automatically.

Is this normal? The reason I'm trying to run it in production is because I am getting errors when I try to deploy my app into heroku ( question asked here: Rails + Heroku : ActionView::Template::Error ) so I thought it would help me debug.


Solution

  • This error is normal when trying to access Rails via SSL when it is run with rails server, unless you hack the default rails server script to support SSL. You can see this blog post for how to do that. That said, I'd recommend simply not accessing your application via SSL on your local machine.

    You probably have a configuration in your Rails app that is redirecting to SSL when you are running the production environment. Try temporarily commenting out that configuration so that you can run in production without needing to configure SSL on your local machine.

    Look in production.rb for:

    config.force_ssl = true
    

    Or, look in application_controller.rb (or any other controller) for:

    force_ssl
    

    Note: they have the same name, but under the hood they work very differently.

    Alternatively, you could run Rails on your local machine via some other web server besides rails server, but that is outside the scope of this question, and you would still have to configure it to support SSL. Personally I have nginx (with unicorn) setup on my local machine with a self-signed SSL certificate so that I can easily test SSL-related behavior in my app.

    Also, you might consider alternate ways to debug your application besides running it in production on your local machine, but exactly how to do that depends on the nature of the bug you're trying to debug.