报错信息(nginx日志):

// :: [crit] #: * stat() "/home/xiaoju/webroot/c-api-intl/app/htdocs/user/getUserInfo" failed (: Permission denied), client: 172.21.205.25, server: localhost, request: "GET /user/getUserInfo HTTP/1.1", host: "10.96.83.130:8005"
// :: [crit] #: * stat() "/home/xiaoju/webroot/c-api-intl/app/htdocs/user/getUserInfo" failed (: Permission denied), client: 172.21.205.25, server: localhost, request: "GET /user/getUserInfo HTTP/1.1", host: "10.96.83.130:8005"
// :: [error] #: * FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.21.205.25, server: localhost, request: "GET /user/getUserInfo HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "10.96.83.130:8005"

意思就是找不到php的入口脚本,那么查看nginx配置是否有问题,主要关注以下配置中标红的部分:

 location ~ \.php$ {
fastcgi_pass 127.0.0.1:;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param ENV_CAPI_DEBUG true;
fastcgi_param APP_ENV development;
include fastcgi_params;
}

我们也可以加nginx日志来验证 SCRIPT_FILENAME 是否配置正确:

# add to nginx.conf
log_format scripts '$document_root$fastcgi_script_name > $request'; # add to server conf block
access_log /var/log/nginx/scripts.log scripts;

做好以上配置之后重启nginx并请求,同时tail -f /var/log/nginx/scripts.log,查看输出的php脚本能不能找到。

我这里输出是这样的:

/home/xiaoju/webroot/c-api-intl/app/htdocs/index.php > GET /user/getUserInfo HTTP/1.1

如果找不到该文件,重新配置nginx,保证php入口脚本能被找到。

如果已经找到该文件,而且还报此错误,那就是权限问题了:运行php-fpm的linux用户没权限访问php入口文件的权限。

我这里运行php-fpm的用户是nginx。(在/usr/local/php/etc/php-fpm.conf配置文件中配置的)

sudo -u nginx stat /home/xiaoju/webroot/c-api-intl/app/htdocs/index.php

果然权限不足,解决办法:

chown nginx:nginx /home/xiaoju/webroot/c-api-intl
chmod g+x /home
chmod g+x /home/xiaoju
chmod g+x /home/xiaoju/webroot

问题解决。

如果中途出现:account is currently not available

vipw /etc/passwd

把对应用户的/sbin/nologin 改成 /bin/bash。

参考文档:

https://www.jianshu.com/p/ce968818497b

https://www.e-learn.cn/content/wangluowenzhang/299721

https://blog.csdn.net/shaobingj126/article/details/7466583

nginx+php-fpm 报错Primary script unknown的更多相关文章

  1. [PHP] 安装PHP报错“Primary script unknown”的解决方法

    当安装完最新版的nginx和最新版的PHP以后,使用niginx默认配置文件中的PHP配置会有错误访问指定目录下的php文件时,显示File not found.错误.查看nginx的错误日志显示 9 ...

  2. 解决nginx FastCGI sent in stderr: “Primary script unknown”

    今天重启了mac,突然发现本地的 lnmp 服务不能用了,什么请求都返回了: FastCGI sent in stderr: "Primary script unknown" 这个 ...

  3. PHP Primary script unknown 终极解决方法

    相信很多配置php环境的都遇到过这个恼人的问题: 浏览器访问php文件,返回来 File not found 查看/var/log/nginx/error.log ,有 “Primary script ...

  4. Nginx-Primary script unknown的报错的解决方法

    配置nginx时一直报错:file not found 错误日志: [error] 12691#0: *6 FastCGI sent in stderr: "Primary script u ...

  5. Nginx+PHP配置错误,日志:[error] 24324#0: *31 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream

    一.问题现象 1.安装nginx.php.php-fpm后,浏览器访问php报错,“File not found”: 二.问题排查 1.检查nginx.php-fpm服务是否正常启动,均正常启动: 2 ...

  6. nginx FastCGI错误Primary script unknown解决办法

    在centos上成功编译安装nginx 1.4.php 5.4并成功启动nginx和php-fpm后,访问php提示"File not found.",同时在错误日志中看到: 复制 ...

  7. Nginx配置SSL报错 nginx: [emerg] unknown directive "ssl"

    Nginx配置SSL报错 nginx: [emerg] unknown directive "ssl"     出现如图所示错误,处理办法如下 去nginx解压目录下执行 ./co ...

  8. 【nginx】 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream

    2013/10/22 20:05:49 [error] 12691#0: *6 FastCGI sent in stderr: "Primary script unknown" w ...

  9. NGINX+PHP-FPM7 FastCGI sent in stderr: “Primary script unknown”

    https://www.cnblogs.com/hjqjk/p/5651275.html 一开始是Nginx打开网页显示一直是拒绝访问.查看nginx日志是报错显示我的题目,然后就各种搜索解决啊! 百 ...

随机推荐

  1. AWS CLI command example

    1.list ec2 instance-id, instance status, type, ip address, name aws ec2 describe-instances --query ' ...

  2. linux+GraphicsMagick 安装

    转摘自:http://blog.csdn.net/fhqsse220/article/details/12995763 GraphicsMagick 安装 下载软件:download:ftp://ft ...

  3. Win7/8 绿色软件开机启动

    在查找番茄工作法PC端软件时,发现了淡高的文章win8绿色软件开机启动,试用了一下wintabs,的确好用! 另外,office软件中有一款 OFFICE tabs的插件,标签式的管理,非常方便快捷, ...

  4. BigDecimal精度问题

    介绍 1.商业计算使用BigDecimal. 2.使用参数为String的构造函数. 3.BigDecimal都是不可变的,每一步的运算时,都会产生一个新的对象.所以在做加减乘除后千万要保存操作后的值 ...

  5. nginx的常规配置

    程序员们,在北上广你还能买房吗? >>>   nginx的常规配置 nginx的使用非常简单,只需要配置好我们需要的各种指令,就能跑起来.如果你需要添加模块,还需要添加模块方面的配 ...

  6. bzoj 2120 线段树套平衡树

    先吐下槽,改了快一个小时,最后发现是SBT的delete写错了,顿时就有想死的心..... 首先对于这道题,我们应该先做一下他的小问题,bzoj1878,虽然和这道题几乎一点关系没有, 但是能给我们一 ...

  7. dependencyManagement和dependencies的区别

    参考:http://zhaoshijie.iteye.com/blog/2094478http://blog.csdn.net/cpf2016/article/details/45674377 还有一 ...

  8. 在 C# 中通过 P/Invoke 调用Win32 DLL

    在 C# 中通过 P/Invoke 调用Win32 DLL 发布日期 : 1/13/2005 | 更新日期 : 1/13/2005 Jason Clark 下载本文的代码: NET0307.exe ( ...

  9. linux常用命令 查看文件

    Linux常用命令 查看文件 cat命令 cat命令的用途是连接文件或标准打印输入并打印.这个命令常用来显示文件内容,或者将几个文件连接起来显示,或者从标准输入读取内容并显示. 命令格式: cat [ ...

  10. eps图片中有中文乱码的问题

    一般的,如果matlab中的fig图片中有中文,直接saveas为eps,eps再插入latex后会出现乱码. 解决的办法为: (1) *.fig利用‘file--print’保存为*.pdf (2) ...