当前位置:首页 > PHP教程 >

nginx FastCGI错误Primary script unknown解决办法

发布时间:2024-03-21 09:23:00 作者:佚名 阅读:(3)

在Nginx中出现"FastCGI错误 Primary script unknown"通常是由于FastCGI配置或PHP-FPM配置的问题导致的。接下来云梦编程就为大家介绍一下FastCGI sent in stderr: "Primary script unknown"的解决方法,有需要的小伙伴可以参考一下

nginx FastCGI错误Primary script unknown解决办法

1、错误提示:

2024/03/10 14:53:31 [error] 10345#0: *54 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 192.168.2.252, server: www.yundreams.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.yundreams.com"

2、解决方法:

    (1)、检查Nginx配置

    确保Nginx配置文件中的FastCGI配置正确指向PHP-FPM的UNIX套接字或TCP地址,并且路径设置正确。

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php-fpm.sock; # 或者 fastcgi_pass 127.0.0.1:9000;
}

    (2)、检查PHP-FPM配置

    确保PHP-FPM配置文件中的listen参数与Nginx配置中的FastCGI地址匹配。配置文件通常位于/etc/php/{version}/fpm/www.conf。

	listen = /var/run/php-fpm.sock

    (3)、检查文件和目录权限

    确保PHP文件和目录的权限设置正确,Nginx用户(一般为www-data)有权限读取PHP文件。

	chown -R www-data:www-data /path/to/your/php/files
	chmod -R 755 /path/to/your/php/files

    (4)、重启服务

    修改配置后,重启Nginx和PHP-FPM服务使更改生效。

	sudo systemctl restart nginx
	sudo systemctl restart php-fpm

    (5)、日志排查

    查看Nginx和PHP-FPM的错误日志,定位具体错误信息,以便更准确地解决问题。

	tail -f /var/log/nginx/error.log
	tail -f /var/log/php-fpm.log


通过以上方法,您可以尝试解决 "FastCGI错误 Primary script unknown" 的问题,确保Nginx和PHP-FPM配置正确,文件权限设置正确,并及时查看日志以便排查问题。

© 2023 - 云梦编程网 版权所有 鲁ICP备2021017318号-4