欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

[转] fastcgi.conf 与 fastcgi_params

程序员文章站 2024-02-21 10:28:16
...

为什么有了 fastcgi_params  还要有 fastcgi.conf

 

fastcgi.conf

 

对比下fastcgi.conffastcgi_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.confnginx 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