403 Forbidden:目录索引为"/path/to/files".被禁止Nginx [英] 403 Forbidden: directory index of "/path/to/files" is forbidden Nginx

查看:255
本文介绍了403 Forbidden:目录索引为"/path/to/files".被禁止Nginx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里我要特别小心,因为我不得不毁坏我的整个服务器并从头开始构建(完全噩梦),因为我尝试按照

I want to be really careful here because I just had to destroy my entire server and build again from scratch (total nightmare) because I tried fixing this error following advice such as

sudo chown -R user:user *
sudo chmod 755 [directory name]
sudo chmod 644 *

并最终严重破坏了我的权限并破坏了整个Ubuntu系统.

and ended up severely screwing up my permissions and breaking the whole Ubuntu system.

我还遵循了其他类似问题的建议,从我的Nginx配置中取出了第二个$uri,但这还没有解决问题.

I've also followed the advice from other similar questions to take out the second $uri from my Nginx config and that has not fixed the problem.

我的user1具有usermod -aG sudo user1

我的Nginx错误日志说

My Nginx error log says

2019/03/06 17:45:40 [error] *1 directory index of "/home/user1/app/src/apr/" is forbidden

我的域名显示

403 Forbidden

ps -ef | grep nginx返回

root     15419     1  0 17:45 ?        00:00:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data 15420 15419  0 17:45 ?        00:00:00 nginx: worker process
user1  15503 15462  0 18:00 pts/1    00:00:00 grep --color=auto nginx

我的nginx配置

server {
    listen 80;
    #listen [::]:80 ipv6only=on;

    server_name your.server.com;
    access_log /etc/nginx/access.log;

    root /var/www/html/someroot;

    location / {
            #autoindex on;

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

            #proxy_set_header X-Real-IP $remote_addr;
            #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            #proxy_set_header Host $http_host;
            #proxy_set_header X-NginX-Proxy true;
            #proxy_pass http://127.0.0.1:8080/;
            #proxy_redirect off;
            #proxy_http_version 1.1;
            #proxy_set_header Upgrade $http_upgrade;
            #proxy_set_header Connection "upgrade";

            #proxy_redirect off;
            #proxy_set_header   X-Forwarded-Proto $scheme;
            #proxy_cache one;
            #proxy_cache_key sfs$request_uri$scheme;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/some/fullchain.pem;
    # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/some/privkey.pem; 
    # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot

    if ($scheme != "https") {
        return 301 https://$host$request_uri;
    }
}

推荐答案

首先,我必须将其添加到我的Nginx配置中,该配置是通过

First, I had to add this to my Nginx config which I found out via another question I asked.

upstream socket {
    ip_hash;
    server $DAPHNE_IP_ADDRESS$ fail_timeout=0;
}

server {
...

location / {
    proxy_pass http://socket;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}

...
}

这时,我看到了404 Error.我通过将try_files $uri =404;更改为try_files $uri $uri/ =404;来解决该问题,但是这导致除主页以外的所有页面上都出现403 Forbidden.关键是完全删除try_files;,该应用程序现在可以正常运行了.

At this point, I was seeing a 404 Error. I solved that by changing try_files $uri =404; to try_files $uri $uri/ =404; however that caused a 403 Forbidden to occur on all pages except for the home page. The key was to take out try_files; altogether and the application now works perfectly.

我还通过遵循渠道文档来设置Supervisord连续运行Daphne.

I also set up Supervisord by following the Channels Docs to run Daphne continuously.

这篇关于403 Forbidden:目录索引为"/path/to/files".被禁止Nginx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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