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

环境: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. 使用 ipmitool 实现远程管理Dell 系列服务器

    IBM 文档:       http://www.ibm.com/developerworks/cn/linux/l-ipmi/index.html ipmi命令收集: http://hi.baidu ...

  2. Android-Kotlin-抽象类与多态的表现

    选择包名,然后右键: 选择Class类型,会有class:  选择File类型,不会自动有class: 目录结构: 定义描述抽象类 Person人类: package cn.kotlin.kotlin ...

  3. 使用HAProxy实现sql server读库的负载均衡

    前置条件 使用sqlserver的发布订阅功能实现读写分离,并创建多个读库. 本文的负载均衡是针对多个读库而言的. 测试环境 vmware 10 64位 windows server 2008 R2 ...

  4. Windows核心编程:第6章 线程基础

    Github https://github.com/gongluck/Windows-Core-Program.git //第6章 线程基础.cpp: 定义应用程序的入口点. // #include ...

  5. Android开发教程 - 使用Data Binding(五)数据绑定

    本系列目录 使用Data Binding(一)介绍 使用Data Binding(二)集成与配置 使用Data Binding(三)在Activity中的使用 使用Data Binding(四)在Fr ...

  6. Python-实现图表绘制总结

    Numpy是Python开源的数值计算扩展,可用来存储和处理大型矩阵,比Python自身数据结构要高效: matplotlib是一个Python的图像框架,使用其绘制出来的图形效果和MATLAB下绘制 ...

  7. 09_python_初始函数

    一.定义 函数是对功能和动作的封装 def functionname( parameters ): "函数_文档字符串" function_suite return [expres ...

  8. jQuery基础(4)- 位置信息、事件流、事件对象、事件代理、jquery事件

    一.jQuery的位置信息 jQuery的位置信是JS的client系列.offset系列.scroll系列封装好的一些简便api. 1.宽度和高度 a.获取宽度和高度,例如: .width() // ...

  9. 文件寄生——寻找宿主的不归路(NTFS文件流实际应用)

    咱们今天来研究下NTFS文件流: NTFS文件系统实现了多文件流特性,NTFS环境一个文件默认使用的是未命名的文件流,同时可创建其他命名的文件流,windows资源管理器默认不显示出文件的命名文件流, ...

  10. Dubbo原理实现之与spring融合

    Spring中bean的定义可以通过编程,可以定义在properties文件,也可以定义在通过xml文件中,用的最多的是通过xml形式,由于xml格式具有很好的自说明便于编写及维护.对于xml的文档结 ...