环境 centos8,编译方式安装的nginx/1.20.1, php 是dnf安装的php/7.2.24

nginx 执行用户、php 执行用户、文件权限都检查了,确定没有问题

nginx 的php配置也确定没有问题,但就是访问php页面出现 File not found

查看nginx报错内容,看到如下错误:"Primary script unknown"

2021/07/07 20:40:02 [error] 8853#0: *164 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 192.168.1.95, server: localhost, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/www.sock:", host: "192.168.1.69"

最终解决的方法:

#/www/wwwroot/phpwebdir/是我的网站根目录
chcon -R -t httpd_sys_content_t /www/wwwroot/phpwebdir/
chcon -R -t httpd_sys_content_t /www/server/nginx/sbin/nginx 
/www/server/nginx/sbin/nginx -s reload

原因是selinux 在作祟,如上命令是配置 网站目录和nginx执行文件的 selinux 上下文
具体selinux这个安全机制至今还没有搞明白咋玩
用以下命令可以查看文件或目录的上下文

ll -dZ /www/wwwroot/phpwebdir/

修改之前是

drwxrw-rw-. 7 www www unconfined_u:object_r:admin_home_t:s0 4096 Jul  7 20:28 /www/wwwroot/phpwebdir/

修改之后是

drwxrw-rw-. 7 www www unconfined_u:object_r:httpd_sys_content_t:s0 4096 Jul  7 20:28 /www/wwwroot/phpwebdir/

或者干脆关闭selinux(需要重启服务器)
/etc/selinux/config :

SELINUX=disabled

标签: nginx

仅有一条评论

  1. 纯顶。不过内容很好

添加新评论