nginx解析PHP程序报错的解决方案

[[email protected] log]# tail -f nginx/error.log
2019/07/31 01:51:02 [error] 26151#0: *52 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 192.168.1.124, server: localhost, request: "GET /test.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "192.168.1.136"
nginx解析PHP页面时无法显示出来,查看nginx日志,报错信息如上;
查看资料
原因:
在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那一行的值)。
解决方案1
在配置最后一行包含fastcgi.conf配置文件,结果如下

 1    location ~ \.php$ {
 2             root           html/wordpress;
 3             fastcgi_pass   127.0.0.1:9000;
 4             fastcgi_index  index.php;
 5             fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
 6             include        fastcgi_params;
 7             include        fastcgi.conf;
 8     }

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

1     location ~ \.php$ {
2           root           html/wordpress;
3           fastcgi_pass   127.0.0.1:9000;
4            fastcgi_index  index.php;
5           fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
6           include        fastcgi_params;
7    }

原文地址:https://blog.51cto.com/14101466/2429115

时间: 2024-08-25 17:54:47

nginx解析PHP程序报错的解决方案的相关文章

nginx搭建php程序报错解决---TP框架

1.TP框架中 出现如下错误: 访问网站 http://192.168.0.204/ STORAGE_WRITE_ERROR_:./Runtime/Cache/Home/51620d75af91aa77adc53082d1113d54.php错误位置FILE: /www/wwwroot/default/ThinkPHP/Library/Think/Storage/Driver/File.class.php LINE: 47 TRACE#0 /www/wwwroot/default/ThinkPH

关于在使用sparksql写程序是报错以及解决方案:org.apache.spark.sql.AnalysisException: Duplicate column(s): "name" found, cannot save to file.

说明: spark --version : 2.2.0 我有两个json文件,分别是emp和dept: emp内容如下: {"name": "zhangsan", "age": 26, "depId": 1, "gender": "male", "salary": 20000} {"name": "lisi", "ag

SharePoint 2013 创建web应用程序报错"This page can’t be displayed"

错误描述 This page can't be displayed ?Make sure the web address http://centeradmin is correct. ?Look for the page with your search engine. ?Refresh the page in a few minutes. 发生过程 创建web应用程序,填写完基本信息以后点击确定,就是"这不会花费很长时间"的提示,然后就报错了,并且SharePoint和iis的日志中

程序报错:Probable fatal error:No fonts found.

今天,使用java写一个验证码,发布到linux服务器上,验证码不能正常显示, 程序报错:Probable fatal error:No fonts found. 经排查项目中使用了new Font("DIALOG", Font.PLAIN, fsize),即名称为"DIALOG"的字体. 解决方案:服务器上装载对应语言包支持 yum groupinstall chinese-support

Nginx部署Django项目报错 KeyError: 'REQUEST_METHOD'

这个问题是应为Nginx的配置文件有问题: 要使用uwsgi启动Django的话要有以下配置: upstream djangos14{ # nginx负载均衡配置: server 10.0.0.10:9999; #server 10.0.0.11:80; } server { listen 80; server_name www.s14hanju.com; location / { # 要使用uwsgi,代理就不要用proxy_pass了,要使用uwsgi_pass: uwsgi_pass dj

Control character in cookie value, consider BASE64 encoding your value , java操作cookie遇到中文会报错的解决方案

项目当中用到cookie保存中文,但是会报如下错误: Control character in cookie value, consider BASE64 encoding your value 大概意思是保存到cookie当中的值存在控制字符,无法保存.但实际上数据是不存在这种问题的.再看后面的那句话,好像是将要保存的值进行了base64编码,可能是因为中文在编码时出现乱码导致一些控制字符的出现.看来setCookie方法不支持保存中文(GBK)编码的样子. 解决方案:将要保存的值进行URLE

jsonkit 解析nsarray 时候 报错

jsonkit 解析nsarray 时候 报错 Assertion failure in -[TXJKArray count], /Users/mqq/hudson/1740/src/TencentOpenApi_IOS/Common/Util/JSONKit.m:738 解决办法: Had the same issue, I was trying to set the output straight to a dictionary I had created. myDictionary = [

运行编译后的程序报错 error while loading shared libraries: lib*.so: cannot open shared object file: No such file or directory

运行编译后的程序报错  error while loading shared libraries: lib*.so: cannot open shared object file: No such file or directory -------------------------------------------------------------------------------------------------------------------------------------

winserver2003环境发布ASP程序报错(HTTP 错误 403.1 - 禁止访问:执行访问被拒绝)

问题: 在Windows Server 2003 + IIS6.0上布署.Net 2.0网站时发生如下错误: 该页无法显示 您试图从目录中执行 CGI.ISAPI 或其他可执行程序,但该目录不允许执行程序. -------------------------------------------------------------------------------- 请尝试以下操作: 如果您认为该目录应该允许执行访问权限,请与网站管理员联系. HTTP 错误 403.1 - 禁止访问:执行访问被