简体   繁体   English

403 Forbidden Rails应用程序w / Nginx,Passenger

[英]403 Forbidden on Rails app w/ Nginx, Passenger

First off, apologies: I know the 403 Forbidden question is a common one for Rails/Nginx installs, but none of the answers I've read so far have solved it for me. 首先,道歉:我知道403 Forbidden问题是Rails / Nginx安装的常见问题,但到目前为止我所读到的答案都没有为我解决。

Disclaimer: This is my first time deploying a Rails app somewhere that isn't Heroku. 免责声明:这是我第一次在某个不是Heroku的地方部署Rails应用程序。 Please be gentle. 请温柔。 ;) ;)

Situation: I have a Rails app running on an Ubuntu 12.04 server, running Nginx (installed with Passenger). 情况:我在Ubuntu 12.04服务器上运行了一个Rails应用程序,运行Nginx(与Passenger一起安装)。

I've deployed my app to my server correctly, but when I attempt to access the site, I receive a 403 Forbidden error. 我已将我的应用程序正确部署到我的服务器,但当我尝试访问该站点时,收到403 Forbidden错误。

Checking my error logs, I see: 检查我的错误日志,我看到:

2013/10/23 22:47:01 [error] 27954#0: *105 directory index of "/var/www/colepeters.com/current/public/" is forbidden, client: 50.3…server: colepeters.com, request: "GET / HTTP/1.1", host: "colepeters.com"
2013/10/23 22:47:10 [error] 27954#0: *106 directory index of "/var/www/colepeters.com/current/public/" is forbidden, client: 184…server: colepeters.com, request: "GET / HTTP/1.1", host: "colepeters.com"
2013/10/23 22:47:12 [error] 27954#0: *107 directory index of "/var/www/colepeters.com/current/public/" is forbidden, client: 151…server: colepeters.com, request: "GET / HTTP/1.1", host: "colepeters.com"

However, when checking permissions on this directory, I see that the user I have setup to use Nginx had both read and execute permissions on it. 但是,在检查此目录的权限时,我看到我设置为使用Nginx的用户对其具有读取和执行权限。

Here's the relevant info from my nginx.conf: 这是我的nginx.conf中的相关信息:

user  XXXX;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    passenger_root /home/cole/.rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.21;
    passenger_ruby /home/cole/.rvm/wrappers/ruby-2.0.0-p247/ruby;

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

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
       listen       80;
        server_name  colepeters.com www.colepeters.com;
        passenger_enabled on;
        root /var/www/colepeters.com/current/public/;
        rails_env production;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
          root   /var/www/colepeters.com/current/public;
          index  index.html index.htm;
          # autoindex on;
        }

I would greatly appreciate any help on resolving this. 我非常感谢有关解决这个问题的任何帮助。 Thanks! 谢谢!

UPDATE I have since corrected the erroneus passenger_ruby path, but the 403 Forbidden is persisting, even after restarting Nginx. 更新我已经纠正了错误的passenger_ruby路径,但403 Forbidden仍然存在,即使在重新启动Nginx后也是如此。

You can check the path of your passenger installation with 您可以使用以下方式检查乘客安装的路径

passenger-config --root

and the path of your ruby installation with 和ruby安装的路径

which ruby

then compare with the inserted in nginx.conf. 然后与插入的nginx.conf进行比较。

I got the same error. 我得到了同样的错误。 In my case, I fixed it by removing the location / {} entry. 就我而言,我通过删除位置/ {}条目来修复它。 - or make sure that your user have permission to your rails project - 或确保您的用户拥有rails项目的权限

...
server {
    listen       80;
    server_name  127.0.0.1;
    passenger_enabled on;
    rails_env production;
    root /www/kalender/public ;

    #charset koi8-r;

    access_log  /var/log/nginx/host.access.log;

    #location / {
       #root   html;
        #index  index.html index.htm;
    #}

Adding passenger_enabled on; 添加passenger_enabled on; to the server directive worked for me. 服务器指令对我有用。

I was running a similar setup to yours and having the same problem with my nginx.conf file. 我正在运行与您类似的设置,并且在我的nginx.conf文件中遇到了同样的问题。 Stumbling across the Nginx pitfalls page helped me solve it. Nginx陷阱页面上磕磕绊绊帮助我解决了这个问题。

Your file looks similar to mine, so I'll share two things you may want to try that worked for me: 你的文件看起来和我的相似,所以我会分享你想尝试的两件对我有用的东西:

  1. first, you have the root path in both the server {} block AND the location {} block. 首先,您在server {}块和location {}块中都有root路径。 While not necessarily a problem, according to the docs linked above "If you add a root to every location block then a location block that isn't matched will have no root." 虽然不一定是个问题,但根据上面链接的文档“如果你向每个位置块添加一个根,那么一个不匹配的位置块将没有根。” I got rid of the roots in the location blocks but kept it in the server block. 我摆脱了位置块的根,但保留在服务器块中。

  2. move the 'index' directives ( index index.html index.htm; ) out of the location block up to within the http {} block. 将'index'指令( index index.html index.htm; )从位置块中移出到http {}块内。 The location blocks will inherit from this. 位置块将继承此。

doing those two things and restarting the server worked for me. 做这两件事并重新启动服务器对我有用。

The problem lies in the location / {...} section: the passenger_enabled on doesn't propagate from the server {...} into the location / {...} . 问题出在location / {...}部分: passenger_enabled on不会从server {...}传播到location / {...}

If you either remove location / {...} , or add passenger_enabled on to it, it should work. 如果你删除location / {...} ,或者passenger_enabled onpassenger_enabled on添加passenger_enabled on ,它应该有效。

The key things are: Remove the location block for the / section, assuming that the Rails application is accessible at / 关键是:删除/ section的位置块,假设可以在/访问Rails应用程序

Ensure the passenger_ruby is pointing to the rvm wrapper script for the selected ruby version 确保passenger_ruby指向所选ruby版本的rvm包装器脚本

Add execute permissions to user, group and others to all the directories reaching to 向用户,组和其他人添加执行权限到达到的所有目录

/var/www/rails_app/public folder 
/var
/var/www
/var/www/rails_app
/var/www/rails_app/public_foler 

you also have config-file for passenger called passenger.conf by default in /etc/nginx/conf.d/passenger.conf there you have to put correct roots. 你也有/etc/nginx/conf.d/passenger.conf默认的乘客配置文件,名为passenger.conf ,你必须把正确的根。 you can check the roots with these two commands 你可以用这两个命令检查根

passenger-config --root

and

which ruby 哪个红宝石

so when you get these roots you have to compare them with such in your passenger.conf file and it can be eg smth like this 因此,当你得到这些根时,你必须将它们与你的passenger.conf文件中的它们进行比较,它可以像这样smth

#passenger-config --root
passenger_root /usr/share/ruby/vendor_ruby/phusion_passenger/locations.ini;
#which ruby
passenger_ruby /usr/local/rvm/rubies/ruby-2.4.0/bin/ruby;
passenger_instance_registry_dir /var/run/passenger-instreg;

so if you use this way don't forget to make in http section of your nginx.conf 因此,如果您使用这种方式,请不要忘记在您的nginx.conf http部分中创建

include /etc/nginx/conf.d/passenger.conf

as well as inserting in server section 以及插入服务器部分

passenger_enabled on;

You are declaring the root twice inside the server block and inside the /location block as well as directing nginx to use the index directive. 您在服务器块内部和/ location块内声明了两次root,并指示nginx使用index指令。 Also remove the "/" after public folder 同时删除公用文件夹后的“/”

try doing this 试着这样做

user  XXXX;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    passenger_root /home/cole/.rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.21;
    passenger_ruby /home/cole/.rvm/wrappers/ruby-2.0.0-p247/ruby;

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

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
       listen       80;
        server_name  colepeters.com www.colepeters.com;
        passenger_enabled on;
        root /var/www/colepeters.com/current/public;
        rails_env production;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM