Ruby on rails 403/尝试使用SSL运行Rails 4应用程序时出现禁止的错误

Ruby on rails 403/尝试使用SSL运行Rails 4应用程序时出现禁止的错误,ruby-on-rails,ssl,nginx,Ruby On Rails,Ssl,Nginx,我正试图让我的Rails 4在带有Ubuntu和NginX的VPS上使用SSL。我从中检索到SSL证书,服务器上的安装似乎已成功 但是,我无法让我的应用程序使用https。目前它只适用于http 当我试图通过https在浏览器中访问它时,我遇到以下错误: 2014/06/04 18:05:56[错误]23306#0:*3“/home/rails/public/index.html”被禁止(13:权限被拒绝),客户端:23.251.149.69,服务器:myapp.com,请求:“GET/HTTP

我正试图让我的Rails 4在带有Ubuntu和NginX的VPS上使用SSL。我从中检索到SSL证书,服务器上的安装似乎已成功

但是,我无法让我的应用程序使用https。目前它只适用于http

当我试图通过https在浏览器中访问它时,我遇到以下错误:

2014/06/04 18:05:56[错误]23306#0:*3“/home/rails/public/index.html”被禁止(13:权限被拒绝),客户端:23.251.149.69,服务器:myapp.com,请求:“GET/HTTP/1.0”,主机:“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; 
  } 
}
我在这里遗漏了什么?如何修复?

我回答了这个问题,但我在这里也注意到了

您有一个
上游
集合,但没有
代理\u通行证
。我猜你是在用独角兽之类的东西来服务这个应用?您可能需要调整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;
    }
}

令人惊叹的。就这样。非常感谢。最后一件事:如果可能,我如何将任何请求转发到
http
https
?这不起作用吗?你的
重写
对我来说很好。不,当我输入
http://www.myapp.com
在地址栏中,它保持不变,不会转发到
https://www.myapp.com
那太好了。