6

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.

Community
  • 1
  • 1
bigpotato
  • 26,262
  • 56
  • 178
  • 334

3 Answers3

7

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.

Nathan
  • 7,816
  • 8
  • 33
  • 44
  • The link of the blog post you posted seems to be broken. Isn't loading. – dhrubo_moy Aug 10 '16 at 20:42
  • @Dhrubo_moy Try https://gist.github.com/roloenusa/859755/bd122f265835aecac85035fd1ca80d152d06d57c – Nathan Aug 10 '16 at 23:15
  • 3
    Great. Thank you so much. I tried commenting out "config.force_ssl = true" line. But still having the SSL_ERROR_RX_RECORD_TOO_LONG error. – dhrubo_moy Aug 11 '16 at 16:05
4

For me config.force_ssl = true was in config/environments/production.rb

Brad Werth
  • 17,411
  • 10
  • 63
  • 88
Hugo
  • 2,069
  • 22
  • 23
  • That is not true Brad. The previous author suggests "production.rb or application_controller.rb". **In my case** (hoping to help others) "config.force_ssl = true" **is set** in the file "config/environments/production.rb". – Hugo Aug 28 '13 at 07:12
  • also, back then I did not have permissions to add it as a "comment" either. – Hugo Aug 28 '13 at 07:21
0

This error occurred for me when I added my machine's hostname in to /etc/hosts with the same name for ipv4 and ipv6.

So it looked like:

127.0.0.1     localhost MyMachine
::1       ip6-localhost MyMachine

After updating the ipv6 personal machine name to prepend the ip6- then Rails started working.