一、问题现象

1、安装nginx、php、php-fpm后,浏览器访问php报错,“File not found”;

二、问题排查

1、检查nginx、php-fpm服务是否正常启动,均正常启动;

2、检查服务端口号,分别是nginx:81、php:9000

3、查看nginx错误日志 /usr/local/nginx/logs/error.log   tail -n 20 error.log

[error] 24324#0: *31 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream

三、解决方法

1、粘贴错误日志信息到百度,发现是nginx配置文件缺少参数导致,参考链接https://www.cnblogs.com/php-linux/p/6526641.html

首先简单的讲一讲原理,目前主流的nginx+php的运行原理如下:
1> nginx的worker进程直接管理每一个请求到nginx的网络请求。
2> 对于php而言,由于在整个网络请求的过程中php是一个cgi程序的角色,所以采用名为php-fpm的进程管理程序来对这些被请求的php程序进行管理。php-fpm程序也如同nginx一样,需要监听端口,并且有master和worker进程。worker进程直接管理每一个php进程。
3> 关于fastcgi:fastcgi是一种进程管理器,管理cgi进程。市面上有多种实现了fastcgi功能的进程管理器,php-fpm就是其中的一种。再提一点,php-fpm作为一种fast-cgi进程管理服务,会监听端口,一般默认监听9000端口,并且是监听本机,也就是只接收来自本机的端口请求,所以我们通常输入命令 netstat -nlpt|grep php-fpm 会得到:
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      1057/php-fpm
这里的127.0.0.1:9000 就是监听本机9000端口的意思。
4> 关于fastcgi的配置文件,目前fastcgi的配置文件一般放在nginx.conf同级目录下,配置文件形式,一般有两种:fastcgi.conf  和 fastcgi_params。不同的nginx版本会有不同的配置文件,这两个配置文件有一个非常重要的区别:fastcgi_parames文件中缺少下列配置:
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
我们可以打开fastcgi_parames文件加上上述行,也可以在要使用配置的地方动态添加。使得该配置生效。
5> 当需要处理php请求时,nginx的worker进程会将请求移交给php-fpm的worker进程进行处理,也就是最开头所说的nginx调用了php,其实严格得讲是nginx间接调用php。
 

2、修改nginx.conf配置文件,添加 fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name; 到文件中;

1> 第一个大括号 server{ }:不必多说,代表一个独立的server,
2> listen  8011:代表该server监听8011端口 
3> location ~ \.php?.*${ }:代表一个能匹配对应uri的location,用于匹配一类uri,并对所匹配的uri请求做自定义的逻辑、配置。这里的location,匹配了所有带.php的uri请求,例如:http://192.168.244.128:8011/test.php/asdasd  http://192.168.244.128:8011/index.php等
4> root  /share/test:请求资源根目录,告诉匹配到该location下的uri到/share/test文件夹下去寻找同名资源。
5> fastcgi_pass  127.0.0.1:9000:这行开始是本文的重点:这行代码的意思是,将进入到该location内的uri请求看做是cgi程序,并将请求发送到9000端口,交由php-fpm处理。
6> fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;  :这行配置意思是:动态添加了一行fastcgi配置,配置内容为SCRIPT_FILENAME,告知管理进程,cgi脚本名称。由于我的nginx中只有fastcgi_params文件,没有fastcgi.conf文件,所以要使php-fpm知道SCRIPT_FILENAME的具体值,就必须要动态的添加这行配置。
7> include fastcgi_params; 引入fastcgi配置文件
以上就是最简洁版的nginx启动php脚本的最简配置,当重启nginx之后,在/share/test目录下创建一个xx.php文件,输入<?php  echo "hello world"; ?>保存,然后在浏览器中访问localhost:8011/xx.php 就可以在网页上显示hello world了。
 
四、问题验证
1、修改nginx配置文件nginx.conf;

2、重启nginx服务,浏览器访问php文件,成功。

 

Nginx+PHP配置错误,日志:[error] 24324#0: *31 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream的更多相关文章

  1. [error] 1507#0: *22 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 10.0.0.1, server: www.wordpress.com, request: "GET /info.p

    字体比较小,如果你遇到这个问题请仔细的把下面的总结看完. 环境:CentOS6.7.2.6.32-573.el6.x86_64.nginx1.12.2 .php5.5.38 问题:nginx能解析静态 ...

  2. 【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 ...

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

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

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

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

  5. 修复Nginx 502错误:upstream sent too big header while reading response header from upstream

    原文出处:https://www.cnblogs.com/jpfss/p/10237463.html 便于以后参考我复制了过来! cookies的值超出了范围我是说 看看了一下日志 错误502 ups ...

  6. nginx log 错误502 upstream sent too big header while reading response header from upstream

    cookies的值超出了范围我是说 看看了一下日志 错误502 upstream sent too big header while reading response header from upst ...

  7. nginx 错误502 upstream sent too big header while reading response header from upstream

    查看nginx的错误日志,得到以下错误信息:upstream sent too big header while reading response header from upstream按字面意思理 ...

  8. nginx error: upstream prematurely closed connection while reading response header from upstream

    本篇文章由:http://xinpure.com/nginx-error-upstream-prematurely-closed-connection-while-reading-response-h ...

  9. *2 FastCGI sent in stderr: "PHP message: PHP Parse error: syntax error, unexpected '[' in /application/nginx-1.6.3/html/zabbix/index.php on line 32" while reading response header from upstream, clien

    今天呢想学习一下zabbix监控一下我的服务情况,然后就开始安装我的zabbix服务,首先LNMP环境准备好了,Nginx版本为1.6.3,php版本为5.3.27,MySQL版本为二进制包安装的5. ...

随机推荐

  1. AQS: 什么是AQS?

    AQS定义了一套多线程访问共享资源的同步器框架. 许多同步类实现都依赖于它,如常用的ReentrantLock/ReentrantReadWriterLock/CountDownLatch这些类里面都 ...

  2. 37)智能指针(就是自动delete空间)

    1)问题引入: 在java或者在C++中,一旦你new一个东西,那么必然有一个delete与之对应,比如: int main() { int* p= new int(): *p=: delete p: ...

  3. 怎么通过scanf读取一个空白前的字符

    /************************************************************************* > File Name: scanf2.c ...

  4. xcode6 Images.xcassets添加LaunchImage

    不使用LaunchScreen.xib,通过Images.xcassets新建LaunchImage做登陆界面 步骤: 1.创建LaunchImage

  5. [原]CreateFile中的dwShareMode

    原 总结 API  一直对CreateFile的参数dwDesiredAccess和dwShareMode有什么不同不是很清楚,今天重读 windows核心编程的时候终于豁然开朗了. 真是书读百遍,其 ...

  6. oracle 查询表空间

    测试用户连接C:\Users\ZP>sqlplus /nologconn hbcxuser/hbcxpass --查看所有表空间 select * from user_tablespaces-- ...

  7. Scapy-ARPspoof学习

    layout title tag date post Scapy模块学习之ARP欺骗 Python 2018-05-08 from scapy.all import Ether,ARP,sendp,g ...

  8. QT程序中显示中文字体解决办法

    Qt4.7.1 默认没有中文字体库,迅为给用户提供“文泉驿”字体和配置方法.本节需要的 文件在网盘: 用一个简单测试程序说明“文泉驿”字体的配置方法. 在 Qt Creater 新建工程“nihao” ...

  9. 网络流dinic板子

    bool bfs(){ memset(deep,0,sizeof(deep)); queue<int>que; que.push(s); deep[s]=1; while(!que.emp ...

  10. linux chmod命令修改文件权限

    在linux中,使用chmod命令修改一个文件的权限. 首先,我们查看一个文件夹下所有文件的权限 ls -l linux文件或目录的权限分为,读.写.可执行三种权限.文件访问的用户类别分为,文件创建者 ...