【问题标题】:SSL with Rails 3.1: config.force_ssl = true not working in development mode带有 Rails 3.1 的 SSL:config.force_ssl = true 不在开发模式下工作
【发布时间】:2011-12-30 14:53:24
【问题描述】:

我正在使用 sqlite 在 Ubuntu 上以开发模式运行 rails 3.1。 rails 服务器在端口 3000 上运行,我将 nginx 设置为 proxy_pass 端口 80 和 443 到端口 3000。当我将 config.force_ssl = true 放入我的 Application.rb 并重新启动 rails 服务器时,我收到如下错误:

    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.

当我将它改回config.force_ssl = false 并重新启动rails 服务器时,我仍然收到错误[2011-12-30 09:48:02] ERROR bad URI 9W\x0Fe���h=9��ݔ|�#��)�/6\x00\x00H\x00��'。在导轨控制台中。如果我也清除浏览器缓存,这种情况就会消失,一切都会恢复正常。但是如何让force_ssl = true 工作?

这是我的 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         

这是我的 /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;
    }
}

【问题讨论】:

    标签: ssl ruby-on-rails-3.1 nginx


    【解决方案1】:

    我在配置 nginx ssl 服务器时遇到了完全相同的错误消息。那是因为我没有 ssl crt 和 key。在你的 nginx 配置文件中,我注意到有 crt 和 key。那么你确定crt和key都可以吗? 如果您不确定,您可以尝试以下链接来创建 self_assigned crt。 http://devcenter.heroku.com/articles/ssl-certificate-self

    附言我想将此答案作为一个小评论附加,但似乎我没有此权限

    【讨论】:

      【解决方案2】:

      【讨论】:

        猜你喜欢
        • 2018-01-23
        • 1970-01-01
        • 2021-03-27
        • 1970-01-01
        • 1970-01-01
        • 2019-12-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多