问题描述
访问Nginx服务器中.php文件,提示file not found。
Nginx-error.log日志:
/02/07 13:01:38 [error] 26483#26483: *398 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 112.17.247.190, server: _, request: "GET /JudgeOnline/index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "47.98.237.181"
问题分析
1、php-fpm没有找到php脚本文件的所在位置
2、权限不足
解决方案
方法一:修改Nginx配置
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
注:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;#脚本文件请求的路径fastcgi_param SCRIPT_NAME $fastcgi_script_name; #脚本名称 fastcgi_param DOCUMENT_ROOT $document_root; #网站的根目录。在server配置中root指令中指定的值
同时需要确保server中包含root 选项,否则会提示document_root没有定义
例:
location ~ \.php$ {# # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini## # With php5-cgi alone:fastcgi_index index.php;fastcgi_pass 127.0.0.1:9000;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;fastcgi_split_path_info ^(.+\.php)(/.+)$;include fastcgi_params;# # With php5-fpm:}
方法二:修改配置文件权限配置
/usr/local/php7/etc/php-fpm.d/目录下
编辑www.conf
改成了root
修改php-fpm.service
vi /lib/systemd/system/php-fpm.service
-R表示用root 用户启动
重新加载
systemctl daemon-reload
重启
systemctl restart php-fpm
参考文章
/sz-xioabai/p/9916501.html
/weixin_41114593/article/details/82348406
/ljl890705/article/details/77991460
/weixin_41114593/article/details/82348406
/twqzy/article/details/70214031
如果觉得《Nginx+PHP-FPM——Nginx日志:[Primary script unknown] 网页:[file not found. ]解决方案》对你有帮助,请点赞、收藏,并留下你的观点哦!