nginx 读取文件 permission denied
nginx 是在root用户下安装的,静态网页的目录/var/www/html/ 目录下的内容所有者也是root 用户,按照 nginx配置文件中location说明 配置静态文件访问地址。
使用网址访问后出现错误日志显示如下
root@localhost:/etc/nginx# more /var/log/nginx/error.log 2018/07/24 11:06:05 [error] 17823#17823: *21 open() "/var/www/html/show/project/test1.html" failed (13: Permission denied), client: 101.228.94.31, server: _, request: "GET /show/project/test1.html HTTP/1.1", host: "45.78.33.187" 2018/07/24 11:06:06 [error] 17823#17823: *21 open() "/var/www/html/show/project/test1.html" failed (13: Permission denied), client: 101.228.94.31, server: _, request: "GET /show/project/test1.html HTTP/1.1", host: "45.78.33.187" 2018/07/24 11:06:16 [error] 17823#17823: *23 open() "/var/www/html/show/project/test1.html" failed (13: Permission denied), client: 101.228.94.31, server: _, request: "GET /show/project/test1.html HTTP/1.1", host: "45.78.33.187" 2018/07/24 11:06:16 [error] 17823#17823: *23 open() "/var/www/html/show/project/test1.html" failed (13: Permission denied), client: 101.228.94.31, server: _, request: "GET /show/project/test1.html HTTP/1.1", host: "45.78.33.187" 2018/07/24 11:06:22 [error] 17823#17823: *25 directory index of "/var/www/html/show/project/" is forbidden, client: 101.228.94.31, server: _, request: "GET /show/project/ H TTP/1.1", host: "45.78.33.187" 2018/07/24 11:06:22 [error] 17823#17823: *25 directory index of "/var/www/html/show/project/" is forbidden, client: 101.228.94.31, server: _, request: "GET /show/project/ H TTP/1.1", host: "45.78.33.187" 2018/07/24 11:10:02 [error] 17823#17823: *30 open() "/var/www/html/show/project/test1.html" failed (13: Permission denied), client: 101.228.94.31, server: _, request: "GET /show/project/test1.html HTTP/1.1", host: "45.78.33.187" 2018/07/24 11:10:02 [error] 17823#17823: *30 open() "/var/www/html/show/project/test1.html" failed (13: Permission denied), client: 101.228.94.31, server: _, request: "GET /show/project/test1.html HTTP/1.1", host: "45.78.33.187" 2018/07/24 11:30:10 [emerg] 17956#17956: invalid number of arguments in "root" directive in /etc/nginx/sites-enabled/default:47 2018/07/24 11:31:56 [notice] 17960#17960: signal process started 2018/07/24 11:32:02 [error] 17961#17961: *38 open() "/var/www/html/show/project/test1.html" failed (13: Permission denied), client: 101.228.94.31, server: _, request: "GET /show/project/test1.html HTTP/1.1", host: "45.78.33.187" 2018/07/24 11:32:03 [error] 17961#17961: *38 open() "/var/www/html/show/project/test1.html" failed (13: Permission denied), client: 101.228.94.31, server: _, request: "GET /show/project/test1.html HTTP/1.1", host: "45.78.33.187"
修改配置文件的 user 配置,改为 root,默认位置是 /etc/nginx/nginx.cnf。
修改好后重启nginx,使用命令如下
nginx -s reload
重新访问页面正常了。
学习过程中,难免出错。如果您在阅读过程中遇到不太明白,或者有疑问。欢迎指正...联系邮箱crazyCodeLove@163.com
如果觉得有用,想赞助一下请移步赞助页面:赞助一下