一、问题现象

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. Excel VBA发送Email时自动允许Outlook安全对话框

    在Outlook的宏安全性设置如果选择了“为所有宏提供通知” 并且,在[编程访问]中选择了“总是向我发出警告” 在其他VBA中创建邮件过程中,如果修改Recipients或者执行Send方法,都会弹出 ...

  2. C/C++中开平方函数sqrt()的用法

    开平方使用sqrt()函数 使用方法: 包含于math.h头文件 sqrt(float * number),返回number的开平方数,返回值为浮点型 sqrt使用时大多需要要强制类型转化,因为sqr ...

  3. Hardy-Weinberg laws

    I.3 Diploids with two alleles: Hardy-Weinberg laws 假设子代是Aa,AA,aa的概率分别是PAa,PAA,Paa,A的基因概率是P1,a的基因概率是P ...

  4. Android之布局androidmanifest.xml 资源清单 概述

    转载:https://www.cnblogs.com/wytings/p/4083463.html AndroidManifest.xml配置文件对于Android应用开发来说是比较细但又很重要的基础 ...

  5. linux下nfs共享目录

    1. 关掉防火墙    systemctl disable firewalld.service 2. 关掉selinux    vim /etc/selinux/config    修改第七行:    ...

  6. iOS之NSString类型为什么要用copy修饰

    在开发的过程中,只知道NSString类型最好用copy修饰而不能用strong,但是不知道为什么,今天了解了下,总算搞明白了. 如下所示,当修饰符为copy时,因为NSMutableString是N ...

  7. python,openpyxl,读写excel文件

    import openpyxl as oxl from openpyxl.utils import get_column_letter, column_index_from_string import ...

  8. VBA自动点击IE的浏览按钮、自动选择路径、自动关闭打开文件对话框

    VBA调用InternetExplorer操作IE浏览器,自动弹出文件选择对话框时,VBA会处于阻塞状态,你必须手工关闭文件选择对话框,VBA才能继续向后运行. 例如下面网址,就有一个文件浏览按钮: ...

  9. matplotlib.pyplot.contour 简单等高线绘制

    contour(X, Y, Z) X,Y是与Z形状相同的二维数组,可以通过 numpy.meshgrid()创建. numpy.meshgrid()----从坐标向量返回坐标矩阵 生成的x,y坐标矩阵 ...

  10. 73)PHP,session基本操作

    (1)先开启: Session_start(); 也可以通过php.ini配置文件中,自动开启sesssion机制:    Session.auto_start; (2)利用$_SESSION来操作数 ...