centos+nginx+php-fpm+php include fastcgi_params php页面能访问但空白,被fastcgi_params与fastcgi.conf害惨了

今天在centos上折腾这块是发现老是访问页面时,浏览器中提示是200 ok.且访问html后缀却是正常出现内容.

但是访问php后缀却返回空白页面,同时查看所有的log没有发现任何出错信息;

再在nginx.conf中的server中写如果 路径不存在就return 405这样的断句来调试,发现我的配置还是正常能走到那个405.

就是没有内容返回....

找了几个小时.头都快晕了.

还是没有搞明白怎么回事.

最后想想和比较了下fastcgi_params与fastcgi.conf,头已经晕了,看了几眼,没看出差别来了.

我包含的是params这个文件,不是conf这个.我就郁闷死了...怎么回事?

然后想想.是不是试试饮食一下conf这个试试看?

一改变.刷新页面,竟然出来内容了...

再回头仔细看眼二个文件.竟然还是没发现有什么区别....已经全部晕了.

使用二个文件名在网上查找一下,才发现,这二个文件真有区别;

而且还有一个历史.

FASTCGI_PARAMS VERSUS FASTCGI.CONF – NGINX CONFIG HISTORY
Tweet
The nginx source install (and by extension package managers) includes two FastCGI configuration files, fastcgi_params and fastcgi.conf that differ only a tiny bit. To this day they still cause confusion amongst new users due to package managers.

The difference between the two files in the source install is the simple line of:

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
The difference between the two files in most distributions package repositories is nothing, they essentially modified fastcgi_params to match fastcgi.conf.

What this line does is tell PHP which file it should execute, without this nginx and PHP cannot work together. This sounds like a good line to include in the shipped FastCGI configuration file and indeed Igor Sysoev thought so as well. However, due to the configurations of the time this wasn’t as easy as simply adding it in.

Back in the days of 0.6.x when I started using nginx and a few years before this change happened a typical configuration example would look like this.

location ~ \.php$ {
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME /var/www/foo$fastcgi_script_name;
    fastcgi_pass backend;
}
Due to community documentation efforts on the wiki people slowly started using the $document_root variable instead of hard coding the root path, however, many people were still using the above configuration many years later.

Because of how array directives inherit and interact the people using the old configuration style made it impossible to include the line in fastcgi_params. Doing this would have meant that SCRIPT_FILENAME would be defined twice and both would be sent to the backend, potentially causing confusing behaviour.

In 0.8.30 (released: 15th of December 2009) Igor then included fastcgi.conf which was the same as fastcgi_params except including the improved SCRIPT_FILENAME fastcgi_param. This meant that the community could now start recommending people include fastcgi.conf instead of recommending moving SCRIPT_FILENAME into fastcgi_params. New articles on the wiki mostly used this, the popular articles were slowly changed to use it and we were promoting it in the IRC support channel.

Of course, an issue back then was that package managers gave nginx very little love and were many versions behind, usually something like 0.6.x versus 0.8.x. The fastcgi.conf file was not included for these people. When they eventually did update they shipped with a fastcgi.conf and a modified fastcgi_params leaving us with a situation where the source install actually differed from the repository install in a non-significant way. While not often, this does still cause the occasional confusing in the IRC channel.

As an aside, I actually prefer

fastcgi_param SCRIPT_FILENAME $request_filename;
as it takes the alias directive into account, fastcgi_new.conf anyone?

Last updated:Sunday, July 7, 2013

关于上面的说法我理解是:

很久很久以前,大家都是include fastcgi_params,而且在后面加上一句

fastcgi_param SCRIPT_FILENAME /var/www/foo$fastcgi_script_name;

因为这个指令它是数组形态的,并不会说,同名的指令,后面会替换掉前面的.

而nginx的开发者慢慢发现大家写死这个root有问题.或是不方便?

于是给了一个方案,或是说,前面的时候,那块还不能写变量?里面是硬编码写死的?

后面可以了.但是估计很多人还是旧写法,如果直接把这句加入params这个文件的前面话,就会可能跟nginx.conf中同时出现,了二次.就会导致很多莫名的问题,

有可能某些地方会用前面一个指令的路径,而另一个地方会可能用到后面一个指令.

所以,作者保留params,新加一个文件叫fastcgi.conf.

而我却刚好理解成这二个文件是相同的...但是因为没有提供这个指令,所以,导致没有文件发送到php gate中.那么.就返回了空白内容;;;;;;;

我晕死了....几个小时........一段历史......如果在fastcgi.conf上加几下注释说明,让粗心,没有仔细看的我就不会这么惨了....

时间: 2024-10-17 05:21:30

centos+nginx+php-fpm+php include fastcgi_params php页面能访问但空白,被fastcgi_params与fastcgi.conf害惨了的相关文章

centos+nginx+php-fpm+php include fastcgi_params php页面能訪问但空白,被fastcgi_params与fastcgi.conf害慘了

今天在centos上折腾这块是发现老是訪问页面时,浏览器中提示是200 ok.且訪问html后缀却是正常出现内容. 可是訪问php后缀却返回空白页面,同一时候查看全部的log没有发现不论什么出错信息; 再在nginx.conf中的server中写假设 路径不存在就return 405这种断句来调试,发现我的配置还是正常能走到那个405. 就是没有内容返回.... 找了几个小时.头都快晕了. 还是没有搞明确怎么回事. 最后想想和比較了下fastcgi_params与fastcgi.conf,头已经

[Nginx] - PHP+FPM相关的配置

CodeIgniter的配置: worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; fastcgi_connect_timeout 300s; fastcgi_send_timeout 300s; fastcgi_read_timeout

1分钟完美安装最新CentOS+Nginx+PHP-FPM+MySQL

PHP 5.3.1 MySQL 5.0.89 Nginx 0.8.33 或 0.7.65 (可选) 现在,我们可以快速全自动搞定 CentOS + Nginx + PHP-FPM + MySQL 的安装了 这个可比网上流传的什么一键安装包要好得多,强烈推荐此法安装,适合所有菜鸟和高手 我服务器上全用的源代码编译安装,也好不到哪去,还很费劲 我这个装完已经包含PHP的一些常用扩展, PDO,eaccelerator,memcache,tidy等等 先新建一个 repo # vi /etc/yum.

CentOS+Nginx+PHP+MySQL详细配置(图解)

原文地址: http://www.jb51.net/article/26597.htm CentOS+Nginx+PHP+MySQL详细配置(带有图解),需要的朋友可以参考下. 一.安装MySQL 目前web服务器已经很少有跑静态页面的,如果要跑动态网站那当然就离不开数据库,虽然在以前文章中有写MySQL是怎么安装的,但是感觉好久没装MySQL,现在只把步骤贴出来,就不做过多的讲解了 #useradd mysql #tar zxvf mysql-5.0.40.tar.gz #cd mysql-5

[zz]阿里云计算:CentOS+nginx+Django+Postgresql web环境搭建

原文链接: http://www.cnblogs.com/AllStarGIS/p/3788518.html 参考链接: 1. http://www.cnblogs.com/zhouej/archive/2012/03/25/2379646.html 2. http://ec58.com/archives/2836 最近在在万网和阿里云上分别购买了一个域名和一台云服务器,打算用来做点什么.昨天吃完晚饭稍作休息开始对这个新奇的玩意作了些了解并着手配置其运行环境,今早凌晨4点多才弄得7788,为此也

centos nginx下安装phpmyadmin

nginx下安装phpmyadmin: 因为本人在网上搜索安装phpmyadmin大部分使用Apache安装,而线上机器不想使用Apache,最后找到了nginx下安装的也比较复杂,所以就自己写一篇算了. 安装lnmp: 在nginx配置: [[email protected] vhost]# cat /etc/nginx/nginx.conf ********     include vhost/*.conf; [[email protected] vhost]# cd /etc/nginx/

深入理解PHP之:Nginx 与 FPM 的工作机制

完全转载(算是一个收藏了) https://zhuanlan.zhihu.com/p/20694204 网络上有很多关于如何配置 Nginx + FPM 的文章,但它们更多从操作的角度出发,告诉我们怎么做,但却没有告诉我们为什么要这么做,本文从 Nginx 与 FPM 的工作机制出发,探讨配置背后的原理,让我们真正理解 Nginx 与 PHP 是如何协同工作的. 要说 Nginx 与 PHP 是如何协同工作的,首先得说 CGI (Common Gateway Interface) 和 FastC

centos+nginx申请Let's Encrypt 通配符HTTPS证书

Let's Encrypt 宣布 ACME v2 正式支持通配符证书,并将继续清除 Web 上采用 HTTPS 的障碍,让每个网站轻松获取管理证书.消息一出,马上就有热心用户分享出了 Let's Encrypt 通配符 HTTPS 证书的申请方式,下面我们一起来学习下吧! 配置环境: 操作系统:Ubuntu 16.04.2 LTS 配置域名:tinywan.top 具体步骤 1.获取certbot-auto 1 2 3 4 5 # 下载 wget https://dl.eff.org/certb

fastcgi_params 与 fastcgi.conf的差异

fastcgi.conf 对比下fastcgi.conf与fastcgi_params文件,可以看出只有以下差异: Java代码   tctq4master@ddd:/etc/nginx$ diff fastcgi.conf  fastcgi_params 2d1 < fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name; 25a25,26 > > fastcgi_param  SCRIPT_FILENA