Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSL with Rails 3.1: config.force_ssl = true not working in development mode

I am running rails 3.1 in development mode on Ubuntu with sqlite. The rails server is running on port 3000, and I have nginx set up to proxy_pass ports 80 and 443 to port 3000. when I put config.force_ssl = true into my Application.rb and restart the rails server, I get an error that looks like:

    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)

    The page you are trying to view can not be shown because the authenticity of the received data could not be verified.
    Please contact the web site owners to inform them of this problem. Alternatively, use the command found in the help menu to report this broken site.

When I change it back to config.force_ssl = false and restart the rails server, I still get an error, [2011-12-30 09:48:02] ERROR bad URI 9W\x0Fe���h=9��ݔ|�#��)�/6\x00\x00H\x00��'. in the rails console. This goes away and everything is back to normal if I also clear the browser cache. But how do I get force_ssl = true to work?

Here is part of my Application.rb:

    module Regi
      class Application < Rails::Application
        # Settings in config/environments/* take precedence over those specified here.
        # Application configuration should go into files in config/initializers
        # -- all .rb files in that directory are automatically loaded.
        config.generators do |g|
          g.template_engine :haml
        end
        config.force_ssl = true
      end
    end         

And here is my /etc/nginx/sites-enabled/default:

server {
    #listen   80; ## listen for ipv4; this line is default and implied
    #listen   [::]:80 default ipv6only=on; ## listen for ipv6

    root /usr/share/nginx/www;
    index index.html index.htm;

    # Make site accessible from http://localhost/
    server_name localhost;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to index.html
            proxy_pass      http://localhost:3000;  
            try_files $uri $uri/ /index.html;
    }


    #error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
    #
    #error_page 500 502 503 504 /50x.html;
    #location = /50x.html {
    #       root /usr/share/nginx/www;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #       fastcgi_split_path_info ^(.+\.php)(/.+)$;
    #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    #
    #       fastcgi_pass 127.0.0.1:9000;
    #       fastcgi_index index.php;
    #       include fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #       deny all;
    #}
}

# HTTPS server
server {
    listen       443;
    server_name  localhost;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;
    ssl    on;
    ssl_certificate    /usr/local/conf/ssl_keys/server.crt;
    ssl_certificate_key    /usr/local/conf/ssl_keys/server.key;

    location / {
        proxy_pass        http://localhost:3000;
        proxy_set_header  X-Real-IP  $remote_addr;
        # root   html;
        # index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}
like image 944
Hungry Bastard Avatar asked Dec 30 '11 14:12

Hungry Bastard


1 Answers

I've encountered the exact same error message when i configure a nginx ssl server.That's because i didn't have ssl crt and key.And in your nginx configure file,I've notice there has been crt and key.So are you sure both the crt and key are ok? If you are not sure, you can try following link to create self_assigned crt. http://devcenter.heroku.com/articles/ssl-certificate-self

p.s. I want to append this answer as a small comment, but seems I did not have this permission

like image 116
raykin Avatar answered Nov 15 '22 08:11

raykin