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

相关文章

linux下开机自启: 在/etc/init.d目录下新建文件elasticsear...
1、因为在centos7中/etc/rc.d/rc.local的权限被降低了,所以...
最简单的查看方法可以使用ls -ll、ls-lh命令进行查看,当使用...
ASP.NET Core应用程序发布linux在shell中运行是正常的。可一...
设置时区(CentOS 7) 先执行命令timedatectl status|grep &...
vim /etc/sysconfig/network-scripts/ifcfg-eth0 B...