HttpFcgi模块

这个模块允许Nginx 与FastCGI 进程交互,并通过传递参数来控制FastCGI 进程工作。

配置实例:

  1. location / {
  2. fastcgi_pass localhost:9000;
  3. fastcgi_index index.php;
  4. fastcgi_param SCRIPT_FILENAME /home/www/scripts/php$fastcgi_script_name;
  5. fastcgi_param QUERY_STRING $query_string;
  6. fastcgi_param REQUEST_METHOD $request_method;
  7. fastcgi_param CONTENT_TYPE $content_type;
  8. fastcgi_param CONTENT_LENGTH $content_length;
  9. }

语法:

fastcgi_buffers

  1. syntax: fastcgi_buffers the_number is_size;
  2. default: fastcgi_buffers 8 4k/8k;
  3. context: http, server, location
  4. 该指令集设置缓冲区的数量和大小,用于缓存从 FastCGI Server 接收到的数据。默认情况下,一个缓冲区的大小相当于一个页面的大小。根据平台的不同设置为4K/8K

fastcgi_buffer_size

syntax: fastcgi_buffer_size the_size

default: fastcgi_buffer_size 4k/8k

context: http, server, location

This directive sets the buffersize, into which will be read the first part of the response, obtained from the fastcgi server.

In this part of response the small response-header is located, as a rule.

By default, the buffersize is equal to the size of one buffer in directive fastcgi_buffers; however, it is possible to set it to less.

fastcgi_cache

syntax: fastcgi_cache zone;

default: none

context: http, server, location

设置缓存在共享内存中的名称. 一块区域可以被用于不用的地方.

fastcgi_cache_key

syntax: fastcgi_cache_key line ;

default: none

context: http, server, location

设置缓存的key, 例:

  1. fastcgi_cache_key localhost: 9000 $ request_uri;

fastcgi_cache_methods

syntax: fastcgi_cache_methods [GET HEAD POST];

default: fastcgi_cache_methods GET HEAD;

context: main,http,location

GET/HEAD is syntax sugar, i.e. you can not disable GET/HEAD even if you set just

  1. fastcgi_cache_methods POST;

fastcgi_cache_min_uses

syntax: fastcgi_cache_min_uses n

default: fastcgi_cache_min_uses 1

context: http, server, location

TODO: Description.

fastcgi_cache_path

syntax: fastcgi_cache_path /path/to/cache [levels=m:n keys_zone=name:time inactive=time clean_time=time]

default: none

context: http, server, location

TODO: Description.

fastcgi_cache_use_stale

  1. syntax: fastcgi_cache_use_stale [updating|error|timeout|invalid_header|http_500]
  2. default: fastcgi_cache_use_stale off;
  3. context: http, server, location
  4. TODO: Description.

fastcgi_cache_valid

  1. syntax: fastcgi_cache_valid [http_error_code|time]
  2. default: none
  3. context: http, server, location
  4. TODO: Description.

fastcgi_index

  1. syntax: fastcgi_index file
  2. default: none
  3. context: http, server, location
  4. The name of the file which will be appended to the URI and stored in the variable $fastcgi_script_name if URI concludes with a slash.

fastcgi_hide_header

  1. syntax: fastcgi_hide_header name
  2. context: http, server, location
  3. 默认情况下Nginx 不会从FastCGI 进程里给客户端发送"Status" "X-Accel-..." 消息头。这个指令可以用来掩饰别的headers
  4. 如果需要"Status" "X-Accel-..." 消息头,那就需要使用这个指令让FastCGI 强制发送消息头给客户端。

fastcgi_ignore_client_abort

  1. syntax: fastcgi_ignore_client_abort on|off
  2. default: fastcgi_ignore_client_abort off
  3. context: http, server, location
  4. 这个指令用来决定忽略用户取消的请求。

fastcgi_intercept_errors

  1. syntax: fastcgi_intercept_errors on|off
  2. default: fastcgi_intercept_errors off
  3. context: http, server, location
  4. 这个指令用来决定是否要把客户端转向4xx5xx错误页,或允许Nginx自动指定错误页页。
  5. 注意:你需要在此明确错误页,它才是有用的。Igor 曾说:“如果没有定制的处理机制,Nginx不会拦截一个没有缺省页的错误。Nginx 只会拦截一些小的错误,放过其他一些。

fastcgi_param

  1. syntax: fastcgi_param parameter value
  2. default: none
  3. context: http, server, location
  4. 该指令指定的参数,将被传递给FastCGI-server
  5. 它可能使用字符串、变量及其它们的组合来作为参数值。如果不在此制定参数,它就会继承外层设置;如果在此设置了参数,将清除外层相关设置,仅启用本层设置。
  6. 下面是一个例子,对于PHP来说的最精简的必要参数:
  7. fastcgi_param SCRIPT_FILENAME /home/www/scripts/php$fastcgi_script_name;
  8. fastcgi_param QUERY_STRING $query_string;
  9. 参数SCRIPT_FILENAME PHP 用来确定执行脚本的名字,而参数QUERY_STRING 是它的一个子参数。
  10. 如果要处理POST,那么这三个附加参数是必要的:
  11. fastcgi_param REQUEST_METHOD $request_method;
  12. fastcgi_param CONTENT_TYPE $content_type;
  13. fastcgi_param CONTENT_LENGTH $content_length;
  14. 如果PHP 在编译时使用了--enable-force-cgi-redirect选项,设置参数REDIRECT_STATUS 的值为200就是必须的了。
  15. fastcgi_param REDIRECT_STATUS 200;

原文: https://wizardforcel.gitbooks.io/nginx-doc/content/Text/3.9_httpfcgi.html