【问题标题】:rails application on nginx http and https access deniednginx http和https上的rails应用程序访问被拒绝
【发布时间】:2014-12-10 07:22:05
【问题描述】:

我正在使用 Nginx phusion_passenger 在个人服务器上部署 Rails 应用程序。我有带有以下服务器块的站点配置文件。使用此配置,我的 http://192.168.1.121 服务无法工作,而 https://192.168.1.121 因禁止(拒绝访问)错误而失败。

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

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

        passenger_enabled on;
        rails_env production;
        root /home/deploy/www/myrailsapp/current/public;
        index index.html index.htm;

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root html;
        }
} 

server {
       listen 443;
       server_name 192.168.1.121;

       passenger_enabled on;
       rails_env production;
       root /home/deploy/www/myrailsapp/current/public;
       index index.html index.htm;

       ssl on;
       ssl_certificate /etc/nginx/ssl/nginx.crt;
       ssl_certificate_key /etc/nginx/ssl/nginx.key;

       ssl_session_timeout 5m;

       ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
       ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
       ssl_prefer_server_ciphers on;

       error_page 500 502 503 504 /50x.html;
       location / {
               try_files $uri $uri/ =404;
       }
}

production.rb 有 force_ssl: true
此外,如果我删除带有 https 条目的 server {} 块,应用程序在 http 上工作得很好(当然我必须从 production.rb 中注释掉 force_ssl: true )。如果从 https 访问同一目录,我对拒绝访问错误感到非常困惑。
- nginx版本:nginx/1.6.2
- Rails 4.0
- 红宝石 2.1.3
任何帮助表示赞赏。

【问题讨论】:

    标签: ruby-on-rails nginx passenger


    【解决方案1】:

    尝试在与 port 80 配置相同的 server 块上配置 SSL。

    另外,port 443recommended to use the ssl parameter of the listen directive,而不是 ssl on 指令。

    所以是这样的:

    server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;
    
        # Use ssl parameter on the listening socket instead of the 'ssl on' directive
        listen 443 ssl; 
    
        server_name 192.168.1.121;
    
        # Rest of your ssl configuration here
        ssl_certificate /etc/nginx/ssl/nginx.crt;
        ssl_certificate_key /etc/nginx/ssl/nginx.key;
        ssl_session_timeout 5m;
    
        ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
        ssl_prefer_server_ciphers on;
    
        passenger_enabled on;
        rails_env production;
        root /home/deploy/www/myrailsapp/current/public;
        index index.html index.htm;
    
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root html;
        }
    } 
    

    来源和推荐阅读:

    【讨论】:

    • @richsinn,谢谢。我将尝试此更改并更新我的回复。
    猜你喜欢
    • 2015-12-21
    • 2015-07-13
    • 1970-01-01
    • 1970-01-01
    • 2016-06-04
    • 1970-01-01
    • 2021-01-16
    • 1970-01-01
    • 2015-09-20
    相关资源
    最近更新 更多