[转] fastcgi.conf 与 fastcgi_params
为什么有了 fastcgi_params 还要有 fastcgi.conf
fastcgi.conf
对比下fastcgi.conf与fastcgi_params文件,可以看出只有以下差异:
[email protected]:/etc/nginx$ diff fastcgi.conf fastcgi_params
2d1
< fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
25a25,26
>
> fastcgi_param SCRIPT_FILENAME $request_filename;
即fastcgi.conf只比fastcgi_params多了一行
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;
原文网址:http://www.cnblogs.com/skynet/p/4146083.html
=============================
https://blog.martinfjordvald.com/2013/04/nginx-config-history-fastcgi_params-versus-fastcgi-conf/
官网原文节选:
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.
============================================================================
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里包含进来。
参考网址: http://www.shangxueba.com/jingyan/303616.html
推荐阅读
-
[转] fastcgi.conf 与 fastcgi_params
-
submit与onsubmit(转),submitonsubmit_PHP教程
-
Flex uint 使用RGB表示的转换 颜色合成与分解的基本原理[转] 博客分类: Flex flex
-
[转]android 安全与权限(Security and Permissions)(翻译) 博客分类: android转贴 androidpermissionsecurity
-
【转】FastCgi与PHP
-
DateDiff函数在Sql与Access中的区别【转】
-
Java中数组转List的三种方法与对比分析
-
map转string与string转map
-
PHP数组转字符串与PHP字符串转数组的相关方法解析_PHP教程
-
基于Opencv下RGB图像转HSV,并分离成单通道R/G/B与H/S/V 博客分类: Opencv opencv图像分离RGBHSV