简体   繁体   English

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

[英]Rails, Passenger, Nginx, I get “403 Forbidden” but why?

I am trying to run my app through Passenger-Nginx on port 5000 我正在尝试通过5000端口上的Passenger-Nginx运行我的应用程序

On my browser I get '403 Forbidden' and on my nginx error log: 在我的浏览器上,我得到“ 403 Forbidden”,在我的nginx错误日志中:

2016/07/12 17:52:12 [error] 28924#0: *1 directory index of "/var/www/cava/public/" is forbidden, client: YYYY, server: cava, request: "GET / HTTP/1.1", host: "XXXX:5000" 2016/07/12 17:52:12 [错误] 28924#0:* 1目录索引“ / var / www / cava / public /”被禁止,客户端:YYYY,服务器:cava,请求:“ GET / HTTP /1.1“,主机:” XXXX:5000“

On passenger root I use what I get from passenger-config --root but whithout the rvm. 在乘客根目录上,我使用从passenger-config --root获得的内容,但没有rvm。 If I use the passenger root with rvm loaded I get passenger error, but is what I did here right? 如果我使用载有rvm的乘客根目录,则会出现乘客错误,但是我在这里所做的对吗?

For reference my app config and my nginx.conf: 作为参考,我的应用程序配置和我的nginx.conf:

My app config 我的应用程式设定

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;
    #}
}

My nginx.conf 我的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/*;
}

Any help appreciated. 任何帮助表示赞赏。

The error message stated: 错误消息指出:

directory index of "/var/www/cava/public/" is forbidden 目录索引“ / var / www / cava / public /”被禁止

which means that your folder has no index file, or the file that is to be treated as index. 这意味着您的文件夹没有index文件,也没有要被视为索引的文件。

I am not familiar with Passenger, but if you'll try to put there index.html file with content <h1>Hello World</h1> , it will be likely shown. 我不熟悉Passenger,但是如果您尝试在其中放置内容为<h1>Hello World</h1> index.html文件,则可能会显示该文件。


The below is not directly related to this problem, but I'll leave it here for the sake of consistency. 以下内容与该问题没有直接关系,但是为了保持一致,我将其保留在此处。

Solution 1 解决方案1

First, determine what user your nginx runs as 首先,确定您的nginx以哪个用户身份运行

ps ueax|grep 'nginx: worker'|grep -v grep|cut -f1 -d' '
#⇒ www-data

or it might be nobody , but in your case it's www-data according to your conf file. 或可能nobody ,但是根据您的conf文件,它是www-data

Change permissions on /var/www/cava/public : 更改/var/www/cava/public权限:

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

Retry, it should work now. 重试,它现在应该可以工作了。

Solution 2 解决方案2

Make your nginx be running as your user . 使您的nginx 以用户身份运行 At the very top of conf change: conf更改的最顶部:

- user www-data:
+ user tasos;

The latter one is probably more handy for development. 后者可能更便于开发。

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

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