时间:2020-06-12 23:52:35 | 栏目: | 点击:次
查看配置的日志/var/log/nginx/error.log,有 “Primary script unknown”,类似如下:
FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream,
一般情况下,原因只有两个,一个是php-fpm找不到php文件,一个是php-fpm没有权限读取和执行文件。
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
权限问题,也是坑最多的。
1) 进程用户
nginx.conf 里的 user 配置要跟 php-fpm.d/www.conf一致,比如都用 nginx,或者自定义用户,默认是www-data。
nginx.conf :
user www-data; worker_processes auto;php-fpm.d/www.conf :
user = www-data group = www-data然后再查看ps -ef | grep php-fpm和ps -ef | grep nginx,两个的用户是一样的,访问成功了。
drwxrwx--- 6 www-data www-data 4.0K 2019-01-03 13:09 /usr/share/nginx/html -rwxrwx--- 1 www-data www-data 40 2019-01-03 13:09 /usr/share/nginx/html/phpinfo.php测试方法:
sudo -u www-data ls -l /usr/share/nginx/html/还有一种坑就是,配置域名的站点时,location下root一定要写,有时候分开配php时,经常漏掉:
location / {
root /www/vita_web/;
}
location ~ .*\.php$ {
root /www/vita_web/;
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}