字体比较小,如果你遇到这个问题请仔细的把下面的总结看完。

环境:CentOS6.7、2.6.32-573.el6.x86_64、nginx1.12.2 、php5.5.38

问题:nginx能解析静态文件但是不能解析php动态文件,返回404文件未发现错误

原始nginx配置:(这里只给出抛给php程序的配置)

         location ~ \.php$ {
root html/wordpress;
fastcgi_pass 127.0.0.1:;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params; }

解决方案:

  方案一:在配置最后一行包含fastcgi.conf配置文件,结果如下

    location ~ \.php$ {
root html/wordpress;
fastcgi_pass 127.0.0.1:;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params; include fastcgi.conf; }

  方案二:把fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;这一行,改为:fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

结果如下:

     location ~ \.php$ {
root html/wordpress;
fastcgi_pass 127.0.0.1:;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params; }

原因:

在fastcgi_params文件(和nginx.conf文件在同一个目录下)里定义了许多与fastcgi程序相关的变量,当nginx通过fastcgi接口发送请求时它要去定义好的地方去解析相应的变量值,然后交给php去处理,很显然,如果fastcgi获取不了相应的值,那么他就无法把相应请求转发给php程序,自然无法解析。

这个问题的关键在于"Primary script unknown”主脚本未知,也就是fastcgi程序无法找到定义的要执行的脚本,默认的配置文件fastcgi_params定义的变量中并没有$fastcgi_script_name这个变量,但是在fastcgi.conf里定义了。所以我们要么包含这个fastcgi.conf文件,要么把fastcgi_params里的SCRIPT_FILENAME 构建成和fastcgi.conf里的值一样,加上$document_root参数(这个参数的值就代表站点目录root那一行的值)。

[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的更多相关文章

  1. 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 ...

  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. FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream,

    在对nginx添加fastCGI的支持后,然后进行php页面验证,发现页面识别不到,不清楚什么情况,随后google了下,原来是Nginx内置变量问题惹的祸. 1.平台介绍: 1 2 3 4 5 6 ...

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

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

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

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

  6. *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. ...

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

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

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

  9. nginx error.log 提示 [error] 887#887: *58 FastCGI sent in stderr: "PHP message: PHP Warning: mysql_connect(): Headers and client library minor version mismatch. Headers:50556 Library:50637

    0. 1.问题 1.1现象: nginx error.log 提示 [error] 887#887: *58 FastCGI sent in stderr: "PHP message: PH ...

随机推荐

  1. ( 递归 )Fractal -- POJ -- 2083

    http://poj.org/problem?id=2083 Fractal Time Limit: 1000MS   Memory Limit: 30000K Total Submissions:  ...

  2. js 判断字符串中是否包含某个字符串(转载)

    from : https://www.cnblogs.com/ooo0/p/7741651.html String对象的方法 方法一: indexOf()   (推荐) var str = " ...

  3. eclipse查看方法被那些代码调用open call hierarchy

    当我们编写的代码量十分巨大,项目十分复杂的时候,想要查找某一个方法都被其他那些代码调用了是一件十分困难的事,然后Eclipse提供了十分方便的方法用于查看方法都被那些代码调用了. 方法一: 选中要查看 ...

  4. noip第4课作业

    1.    计算邮资 [问题描述] 根据邮件的重量和用户是否选择加急计算邮费.计算规则:重量在1000克以内 (包含1000克),基本费8元.超过1000克的部分,每500克加收超重费4元,不足500 ...

  5. 记一次spring里bean无法注入的历程

    应用启动的时候失败,看了下异常,是这个---NoUniqueBeanDefinitionException. 大家都知道,这是因为有俩个类型相同的实例,在被注入的时候,spring不知道该用哪个. 但 ...

  6. PAT甲级 1120. Friend Numbers (20)

    1120. Friend Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Two in ...

  7. 用jquery将输入的文字的双向绑定

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...

  8. MySQL表名大小写设置

    1 简介    在MySQL中,数据库对应数据目录中的目录.数据库中的每个表至少对应数据库目录中的一个文件(也可能是多个,取决于存储引擎).因此,所使用操作系统的大小写敏感性决定了数据库名和表名的大小 ...

  9. 2.虚拟机安装的ubuntu全屏显示

    虚拟机下面安装了ubuntu系统,显示的屏幕只有那么一小块儿,不知道如何才能全屏,那么如何全屏呢?且看下面经验. 方法/步骤 打开虚拟机,并点击要更改成全屏的那个ubuntu系统的电源 我的虚拟机名字 ...

  10. 工作随笔——获取当前Java程序PID

    小知识,记录下: JVM:1.8 // spring boot 中可以使用 String pid = ManagementFactory.getRuntimeMXBean().getSystemPro ...