对比下fastcgi.conf与fastcgi_params文件,能够看出只有如下差别:php
tctq4master@ddd:/etc/nginx$ diff fastcgi.conf fastcgi_params html
2d1 nginx
< fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 后端
25a25,26 数组
> 服务器
> fastcgi_param SCRIPT_FILENAME $request_filename; app
即fastcgi.conf只比fastcgi_params多了一行ide
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
本来只有fastcgi_params文件,fastcgi.conf是nginx 0.8.30 (released: 15th of December 2009)才引入的。主要为是解决如下问题(参考:http://www.dwz.cn/x3GIJ):
本来Nginx只有fastcgi_params,后来发现不少人在定义SCRIPT_FILENAME时使用了硬编码的方式。
例如,fastcgi_param SCRIPT_FILENAME /var/www/foo$fastcgi_script_name。
因而为了规范用法便引入了fastcgi.conf。
过这样的话就产生一个疑问:
为何必定要引入一个新的配置文件,而不是修改旧的配置文件?
这是由于fastcgi_param指令是数组型的,和普通指令相同的是:内层替换外层;
和普通指令不一样的是:当在同级屡次使用的时候,是新增而不是替换。
换句话说,若是在同级定义两次SCRIPT_FILENAME,那么它们都会被发送到后端,这可能会致使一些潜在的问题,为了不此类状况,便引入了一个新的配置文件。
所以再也不建议你们使用如下方式(搜了一下,网上大量的文章,而且nginx.conf的默认配置也是使用如下方式):
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
而使用最新的方式:
include fastcgi.conf;
php问题 如下两种方式,选用第二种
location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi_params } location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi.conf; }
原文网址:http://www.cnblogs.com/skynet/p/4146083.html
============================================================================
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
这句话其实就是定义php中用到的服务器变量 ——$_SERVER
http://wiki.nginx.org/NginxHttpFcgiModule 这个网址下有这么一句话:
This module allows Nginx to interact with FastCGI processes and control what parameters are passed to the process。
意思是 “服务器” 向你的处理php的cgi传递过去他须要的一些参数,而至少要有下面的两个参数php才能执行起来。
如下是例子
Below is an example of the minimally necessary parameters for PHP:
fastcgi_param SCRIPT_FILENAME /home/www/scripts/php$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
Parameter SCRIPT_FILENAME is used by PHP for determining the name of script. to execute, and QUERY_STRING contains the parameters of the request.
因此 咱们在没有定义SCRIPT_FILENAME这个系统变量的时候 php是无法解释执行的
这个变量的定义能够写在nginx的配置文件nginx.conf里 也能够写在外部 用include的方式在nginx.conf里包含进来。