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

环境: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. (DFS)展开字符串 -- hdu -- 1274

    http://acm.hdu.edu.cn/showproblem.php?pid=1274 展开字符串 Time Limit: 2000/1000 MS (Java/Others)    Memor ...

  2. Leetcode--136. Single Number(easy)

    Given a non-empty array of integers, every element appears twice except for one. Find that single on ...

  3. Linq动态查询与模糊查询 ---转

    Linq动态查询与模糊查询(带源码示例) 继LINQ动态组合查询PredicateExtensions讲解 ----- 在用上面的方法时遇到了些问题 解决 LINQ to Entities 不支持 L ...

  4. 最大m段子段和

    hdu1024 最大m子序列和 给定你一个序列,让你求取m个子段(不想交的子段)并求取这m个子段和的最大值 从二维开始来看dp[i][j]表示取第j个数作为第i个子段的元素所得到的前i个子段和的最大值 ...

  5. Maven中的配置文件

    <span style="padding:0px; margin:0px"><project xmlns="http://maven.apache.or ...

  6. 用Html创建简历

    用最基本的html实现简历的创建 代码 <!doctype html> <html> <head><meta charset="utf-8" ...

  7. AngularJS 杂项知识点

    1.要用ngChange要同时使用ngModel,下拉选择获取当前选中值. 2.打包代替动态加载(js文件) requirejs真正的价值在于模块化,不是动态加载,angularjs本身有模块化机制, ...

  8. 获取物料分类excel公式

    物料格式 大类|中类|小类|名称|.......   =MID(D2,FIND("|",D2,FIND("|",D2)+1)+1,FIND("|&qu ...

  9. ASP.NET Web API 中使用 swagger 来管理 API 文档

    本文以 ASP.NET Web API 为后台框架,利用 EF6 连接 postgreSQL 数据库,使用 swagger 来生成 REST APIs文档.文章分二个部分,第一部分主要讲如何用 EF6 ...

  10. C#常用修饰符

    访问修饰符 访问修饰符是一些关键字,用于指定声明的成员或类型的可访问性,C#有4个访问修饰符:public.private.protected.internal,使用这些访问修饰符可以指定以下5个访问 ...