FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9

在访问php页面时,看log报错:

FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000",

一开始以为是SCRIPT_FILENAME的问题,但发现我的配置:

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

没有问题,后来发现是因为php-fpm配置的问题
php-fpm.d/www.conf这个文件中

user = _www
group = _www

将其改成root(因为我是用root启动的,不建议使用这个用户)
然后又报错:

please specify user and group other than root

php-fpm默认是不允许用root启动的,我在centos7中通过systemctl start php-fpm启动的,为了能使用root启动,将/usr/lib/systemd/system/php-fpm.service这个文件中的

ExecStart=/usr/sbin/php-fpm --nodaemonize

改成

ExecStart=/usr/sbin/php-fpm --nodaemonize -R

然后重新加载并启动

systemctl daemon-reload
systemctl start php-fpm

done

你可能感兴趣的:(FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9)