Rails,Passenger,Nginx,我收到“403 Forbidden”,但为什么?

Rails, Passenger, Nginx, I get "403 Forbidden" but why?

我正尝试通过端口 5000 上的 Passenger-Nginx 运行 我的应用程序

在我的浏览器上出现“403 Forbidden”,在我的 nginx 错误日志中:

2016/07/12 17:52:12 [error] 28924#0: *1 directory index of "/var/www/cava/public/" is forbidden, client: Y.Y.Y.Y, server: cava, request: "GET / HTTP/1.1", host: "X.X.X.X:5000"

在 passenger root 上,我使用从 passenger-config --root 获得的内容,但没有 rvm。 如果我在加载 rvm 的情况下使用 passenger root,我会收到 passenger 错误,但我在这里做的对吗?

参考我的应用程序配置和我的 nginx.conf:

我的应用配置

server {


    listen 5000;

    listen [::]:5000;

    server_name cava;

    root /var/www/cava/public;
    #try_files $uri/index.html $uri @app;

    # Add index.php to the list if you are using PHP
    #index index.html index.htm index.nginx-debian.html;

    #location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        #try_files $uri $uri/ =404;
    #}
}

我的nginx.conf

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

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
    passenger_ruby /home/tasos/.rvm/rubies/ruby-2.3.0/bin/ruby;


    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;

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


    ssl_session_cache  builtin:1000  shared:SSL:10m;
    ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;

    server {

        passenger_enabled on;


        listen 443 ssl;

        root /usr/share/nginx/html;
        index index.html index.htm;

        ssl_certificate /etc/nginx/ssl/1_beast.smartupweb.com_bundle.crt;
        ssl_certificate_key /etc/nginx/ssl/smartup1.key;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers ALL:!DH:!EXPORT:!RC4:+HIGH:+MEDIUM:!LOW:!aNULL:!eNULL;

        #location / {
         #       try_files $uri $uri/ =404;
        #}
}
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

感谢任何帮助。

错误信息指出:

directory index of "/var/www/cava/public/" is forbidden

表示你的文件夹没有index文件,或者是要作为索引的文件。

我对 Passenger 不熟悉,但如果你尝试将内容 <h1>Hello World</h1> 的文件放在那里 index.html,它很可能会显示。


以下内容与此问题没有直接关系,但为了保持一致性,我将其保留在这里。

解决方案 1

首先,确定您的nginx

运行的用户
ps ueax|grep 'nginx: worker'|grep -v grep|cut -f1 -d' '
#⇒ www-data

或者它可能是 nobody,但在你的情况下,根据你的 conf 文件,它是 www-data

更改 /var/www/cava/public 的权限:

sudo chown -R www-data /var/www/cava/public

重试,现在应该可以了。

解决方案 2

让你的 nginx be running as your user。在 conf 的最顶部更改:

- user www-data:
+ user tasos;

后者可能更便于开发。