centos – 403在尝试访问nginx文档根目录中的文件夹时禁止访问

当我访问index.php时,它工作正常.但是在localhost / pset7上,它给出了403.

这是权限日志,

-rw-r--r--. 1 root        root          51 Jul 31 14:21 index.html
-rw-r--r--. 1 root        root          51 Jul 31 14:15 index.php
drwxrwxr-x. 5 my_user my_user 4096 Jul 31 15:13 pset7

我需要在网络服务器上运行它,所以请告诉我如何设置正确的权限并解决这个问题.

在CentOS上使用LEMP.

如果您需要任何其他信息/日志,请询问.

Edit1,nginx config- http://pastebin.com/K3fcWgec

谢谢.

最佳答案
发生这种情况的原因是nginx默认情况下不允许列出目录内容.

因此,如果nginx无法在目录中找到使用index指令指定的文件,它将返回403错误代码.

如果要允许目录列表,可以在配置块中使用autoindex指令:

location /pset7 {
    autoindex on;
}

您还应该将root和index指令从位置/块移动到服务器级别,以便您的配置如下所示:

server {
    listen 80;
    server_name localhost;

    root /var/www/html;
    index index.html index.htm index.php;

    location /pset7 {
        autoindex on;
    }

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php${
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

相关文章

文章浏览阅读3.7k次,点赞2次,收藏5次。Nginx学习笔记一、N...
文章浏览阅读1.7w次,点赞14次,收藏61次。我们在使用容器的...
文章浏览阅读1.4k次。当用户在访问网站的过程中遇到404错误时...
文章浏览阅读2.7k次。docker 和 docker-compose 部署 nginx+...
文章浏览阅读1.3k次。5:再次启动nginx,可以正常启动,可以...
文章浏览阅读3.1w次,点赞105次,收藏182次。高性能:Nginx ...