nginx 配置 PHP 的时候出现 File not found 疑难问题解决方法
环境 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版权属于:Joyber
本文链接:https://blog.qqvbc.com/default/456.html
转载时须注明出处及本声明
纯顶。不过内容很好