Nginx+PHP-fpm 出现 File not found( Primary script unknown)

2015-05-23 01:18:12 +08:00
 imsuwj
```
server {
listen 80;
server_name localhost;
root /home/user/www;
index index.html index.htm index.php;
location ~ \.php$ {
include fastcgi_params;
fastcgi_index index.php;
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
```
LOG的错误是
```
2015/05/23 00:58:54 [error] 6007#0: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/php-fpm.sock:", host: "127.0.0.1"
```
路径没错。其他文件都可以访问。
折腾了一天,不知道如何解决。
Google出来的都是说fastcgi_param配置错误,然而我改了貌似也不行。
8755 次点击
所在节点    PHP
9 条回复
extreme
2015-05-23 01:34:18 +08:00
试试这个:
删掉这行:fastcgi_param SCRIPT_FILENAME
然后用http://downloads.yzs.me/fastcgi_params的替换已有的fastcgi_params。
重启Nginx, PHP FPM。
kslr
2015-05-23 01:56:01 +08:00
看看PHP.INI末尾有没有限制网站目录的
fdb713
2015-05-23 02:47:37 +08:00
确保nginx是最新版(1.8.x)
然后
include fastcgi_params;
改成
include fastcgi.conf
最后nginx -t检查无误后
service nginx restart/systemctl restart nginx
leecade
2015-05-23 03:05:43 +08:00
no

检查权限 nginx / php-fpm 是什么用户
stanhou
2015-05-23 12:58:53 +08:00
你访问哪个文件出现这提示?“其他文件都可以访问”又是什么意思……
bjdchwr
2015-05-23 15:03:44 +08:00
@leecade 同意

我之前就是,404搞了半天最后是目录权限问题,有些目录创建时是sudo的root权限,www用户权限不足
imsuwj
2015-05-23 17:08:37 +08:00
@bjdchwr
@leecade
php-fpm和nginx的用户都是http,用户组为http
我把root路径设为/usr/share/nginx/html的话就没有问题了,/usr/share/nginx/html的所有者为root
但是我想设置root目录到/home/xxx/www 这里,就会403 Forbidden,www文件夹的权限应该设为什么呢?是保持桌面用户还是设成http用户所有?我试过chown -R http:http www,也还是403错误
bjdchwr
2015-05-23 18:23:39 +08:00
@imsuwj 我的命令是这样的

chown -R www-data:www-data /root <----我用HTTP当文件传输工具用,所以简单暴力的直接定义到root目录下然后施加IP限制

貌似UID在我这里是33.。。
ctexlive
2015-06-01 20:16:53 +08:00
你贴出来的是全部配置吗?
“我把root路径设为/usr/share/nginx/html的话就没有问题了”-》从这句话描述,怀疑你的配置文件没贴全,有个默认配置在里面。比如 php那段,有个“root html”。他有默认的路径,可能就是/usr/share/nginx/...
所以如果全局root到别的目录下, 在php段要注释掉这句话,或者手动添加
ocation ~ \.php$ {
root /home/user/www;
fastcgi_index index.php;
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

还有,你的php-fpm.d/www.conf必须设置正确的
-----------------------
user = nginx
group = nginx
listen.owner = nginx #关键和Nginx的运行uid一致
listen.group = nginx #关键和Nginx的运行gid一致
listen.mode = 0660 #关键必须赋予读写权限。实在不行,可以赋予777权限测试
------------------------

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/193120

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX