Rails,Passenger,Nginx,我得到"403 Forbidden"但为什么? [英] Rails, Passenger, Nginx, I get "403 Forbidden" but why?

查看:114
本文介绍了Rails,Passenger,Nginx,我得到"403 Forbidden"但为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to run my app through Passenger-Nginx on port 5000

在我的浏览器上,我得到"403 Forbidden",在我的nginx错误日志中:

On my browser I get '403 Forbidden' and on my nginx error log:

2016/07/12 17:52:12 [错误] 28924#0:* 1的目录索引 禁止使用"/var/www/cava/public/",客户端:Y.Y.Y.Y,服务器: cava,请求:"GET/HTTP/1.1",主机:"X.X.X.X:5000"

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-config --root 中获得的信息,但没有rvm. 如果我使用载有rvm的乘客根目录,会出现乘客错误,但是我在这里所做的对吗?

On passenger root I use what I get from passenger-config --root but whithout the rvm. If I use the passenger root with rvm loaded I get passenger error, but is what I did here right?

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

For reference my app config and my 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/*;
}

任何帮助表示赞赏.

推荐答案

错误消息如下:

"/var/www/cava/public/"的目录索引被禁止

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

这意味着您的文件夹中没有index文件,或该文件将被视为索引.

which means that your folder has no index file, or the file that is to be treated as index.

我对旅客不熟悉,但是如果您尝试将内容为<h1>Hello World</h1>index.html文件放在其中,则可能会显示该文件.

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.

以下内容与该问题没有直接关系,但出于一致性考虑,我将其保留在此处.

The below is not directly related to this problem, but I’ll leave it here for the sake of consistency.

首先,确定您的nginx以哪个用户身份运行

First, determine what user your nginx runs as

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

,也可能是nobody,但根据您的conf文件,它是www-data.

or it might be nobody, but in your case it’s www-data according to your conf file.

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

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

重试,现在应该可以使用.

Retry, it should work now.

使您的nginx 以您的用户身份运行.在conf更改的最顶部:

Make your nginx be running as your user. At the very top of conf change:

- user www-data:
+ user tasos;

后一种可能更便于开发.

The latter one is probably more handy for development.

这篇关于Rails,Passenger,Nginx,我得到"403 Forbidden"但为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆