### HttpFcgi模塊
這個模塊允許Nginx 與FastCGI 進程交互,并通過傳遞參數來控制FastCGI 進程工作。
配置實例:
~~~
location / {
fastcgi_pass localhost:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/www/scripts/php$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
}
~~~
語法:
### fastcgi_buffers
~~~
syntax: fastcgi_buffers the_number is_size;
default: fastcgi_buffers 8 4k/8k;
context: http, server, location
該指令集設置緩沖區的數量和大小,用于緩存從 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, 例:
~~~
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
~~~
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
~~~
syntax: fastcgi_cache_use_stale [updating|error|timeout|invalid_header|http_500]
default: fastcgi_cache_use_stale off;
context: http, server, location
TODO: Description.
~~~
### fastcgi_cache_valid
~~~
syntax: fastcgi_cache_valid [http_error_code|time]
default: none
context: http, server, location
TODO: Description.
~~~
### fastcgi_index
~~~
syntax: fastcgi_index file
default: none
context: http, server, location
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
~~~
syntax: fastcgi_hide_header name
context: http, server, location
默認情況下Nginx 不會從FastCGI 進程里給客戶端發送"Status" 和"X-Accel-..." 消息頭。這個指令可以用來掩飾別的headers 。
如果需要"Status" 和"X-Accel-..." 消息頭,那就需要使用這個指令讓FastCGI 強制發送消息頭給客戶端。
~~~
### fastcgi_ignore_client_abort
~~~
syntax: fastcgi_ignore_client_abort on|off
default: fastcgi_ignore_client_abort off
context: http, server, location
這個指令用來決定忽略用戶取消的請求。
~~~
### fastcgi_intercept_errors
~~~
syntax: fastcgi_intercept_errors on|off
default: fastcgi_intercept_errors off
context: http, server, location
這個指令用來決定是否要把客戶端轉向4xx和5xx錯誤頁,或允許Nginx自動指定錯誤頁頁。
注意:你需要在此明確錯誤頁,它才是有用的。Igor 曾說:“如果沒有定制的處理機制,Nginx不會攔截一個沒有缺省頁的錯誤。Nginx 只會攔截一些小的錯誤,放過其他一些。
~~~
### fastcgi_param
~~~
syntax: fastcgi_param parameter value
default: none
context: http, server, location
該指令指定的參數,將被傳遞給FastCGI-server。
它可能使用字符串、變量及其它們的組合來作為參數值。如果不在此制定參數,它就會繼承外層設置;如果在此設置了參數,將清除外層相關設置,僅啟用本層設置。
下面是一個例子,對于PHP來說的最精簡的必要參數:
fastcgi_param SCRIPT_FILENAME /home/www/scripts/php$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
參數SCRIPT_FILENAME 是PHP 用來確定執行腳本的名字,而參數QUERY_STRING 是它的一個子參數。
如果要處理POST,那么這三個附加參數是必要的:
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
如果PHP 在編譯時使用了--enable-force-cgi-redirect選項,設置參數REDIRECT_STATUS 的值為200就是必須的了。
fastcgi_param REDIRECT_STATUS 200;
~~~
- 主要文檔
- Nginx功能概述
- 為什么選擇Nginx
- Nginx安裝
- 運行和控制Nginx
- 配置符號參考
- 優化 Nginx
- 常見問題(FAQ)
- 調試 nginx
- 核心模塊
- Nginx主模塊
- Nginx事件模塊
- 基本模塊
- http核心模塊
- HttpIndex模塊
- HttpAccess模塊
- HttpAuthBasic模塊
- HttpAutoindex模塊
- Browser模塊
- Charset模塊
- HttpEmptyGif模塊
- HttpFcgi模塊
- Geo模塊
- HttpGzip模塊
- HttpHeaders模塊
- HttpIndex模塊
- HttpReferer模塊
- HttpLimit zone
- HttpLimitReqest模塊
- HttpLog模塊
- map
- Memcached
- HttpProxy模塊
- HttpRewrite模塊
- HttpSSI模塊
- HttpUserId
- 其他模塊
- Addition模塊
- EmbeddedPerl
- flv
- HttpGzipStatic
- RandomIndex
- HttpGeoIP
- HttpRealIp
- HttpSSL
- StubStatus模塊
- HttpSubstitution
- HttpDav模塊
- GooglePerftools
- HttpXSLT
- HttpSecureLink
- HttpImageFilter
- mail模塊
- MailCore
- MailAuth
- MailProxy
- MailSSL
- 安裝
- nginx在windows上的安裝
- nginx在freebsd上的安裝
- nginx在ubuntu上的安裝
- nginx在fedora上的安裝
- nginx php-fpm安裝配置
- 配置示例和方法
- 完整例子
- 完整例子2
- 虛擬主機
- 負載均衡
- nginx防盜鏈
- HWLoadbalancerCheckErrors