【问题标题】:403 / Forbidden error when trying to run Rails 4 app with SSL403 / 尝试使用 SSL 运行 Rails 4 应用程序时出现禁止错误
【发布时间】:2014-06-04 16:35:50
【问题描述】:

我正在尝试让我的 Rails 4 在带有 Ubuntu 和 NginX 的 VPS 上使用 SSL。我从StartSSL.com检索了一个SSL证书,服务器上的安装似乎已经成功了。

但是,我的应用无法使用 https。它目前仅适用于 http。

当我尝试通过 https 在浏览器中访问它时,出现此错误:

2014/06/04 18:05:56 [error] 23306#0: *3 "/home/rails/public/index.html" is forbidden (13: Permission denied), client: 23.251.149.69, server: myapp.com, request: "GET / HTTP/1.0", host: "myapp.com"

这将是我在/etc/nginx/nginx.conf 中的 NGINX 配置文件:

user www-data; 
worker_processes 4; 
pid /var/run/nginx.pid;

events { worker_connections 1024; }

http { 
  sendfile on; 
  tcp_nopush on; 
  tcp_nodelay on; 
  keepalive_timeout 65; 
  types_hash_max_size 2048; 
  server_tokens off;

  server_names_hash_bucket_size 64;

  include /etc/nginx/mime.types; 
  default_type application/octet-stream;

  access_log /var/log/nginx/access.log; 
  error_log /var/log/nginx/error.log;

  gzip on; 
  gzip_disable "msie6"; 
  gzip_types text/plain text/xml text/css text/comma-separated-values; 
  upstream app_server { server 127.0.0.1:8080 fail_timeout=0; }

  include /etc/nginx/conf.d/*.conf; 
  include /etc/nginx/sites-enabled/*;

  server { 
    listen 80; 
    server_name myapp.com; 
    rewrite ^ https://$server_name$request_uri? permanent; 
  }

  server { 
    listen 443; 
    server_name myapp.com; 
    root /home/rails/public;

    ssl on; 
    ssl_certificate /etc/ssl/myapp.com.crt; 
    ssl_certificate_key /etc/ssl/myapp.com.key; 
  } 
}

我在这里缺少什么以及如何解决这个问题?

【问题讨论】:

    标签: ruby-on-rails ssl nginx


    【解决方案1】:

    我回答了这个over on DigitalOcean,但我在这里也注意到了。

    您有一个upstream 集,但没有proxy_pass。我假设您正在使用 Unicorn 之类的东西来为应用程序提供服务?您可能需要调整侦听 443 的服务器块,以充当上游服务器的反向代理。类似的东西:

    server { 
        listen 443; 
        server_name myapp.com; 
        root /home/rails/public;
        index index.htm index.html;
    
    
        ssl on; 
        ssl_certificate /etc/ssl/myapp.com.crt; 
        ssl_certificate_key /etc/ssl/myapp.com.key; 
    
        location / {
                try_files $uri/index.html $uri.html $uri @app;
        }
    
         location @app {
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_redirect off;
                proxy_pass http://app_server;
        }
    }
    

    【讨论】:

    • 太棒了。就是这样。谢谢!最后一件事:如果可能,我如何将任何请求转发到 httphttps
    • 这不起作用吗?你的rewrite 我觉得不错。
    • 不,当我在地址栏中输入http://www.myapp.com 时,它会保持这种状态并且不会转发到https://www.myapp.com 这会很好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-19
    • 2016-12-10
    • 1970-01-01
    相关资源
    最近更新 更多