這個(gè)模塊允許 Nginx 與 FastCGI 進(jìn)程交互,并通過(guò)傳遞參數(shù)來(lái)控制 FastCGI 進(jìn)程工作。
配置實(shí)例:
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;
}
語(yǔ)法:
syntax: fastcgi_buffers the_number is_size;
default: fastcgi_buffers 84k/8k;
context: http, server, location
該指令集設(shè)置緩沖區(qū)的數(shù)量和大小,用于緩存從 FastCGI Server 接收到的數(shù)據(jù)。默認(rèn)情況下,一個(gè)緩沖區(qū)的大小相當(dāng)于一個(gè)頁(yè)面的大小。根據(jù)平臺(tái)的不同設(shè)置為4K/8K
語(yǔ)法: fastcgi_buffer_size 大小
默認(rèn): fastcgi_buffer_size 4k / 8k
環(huán)境: http, server, location
該命令設(shè)置緩沖區(qū)大小,其中將讀取第一部分的輸出,從 fastcgi 服務(wù)端獲取
在這個(gè)輸出的小輸出標(biāo)頭部分的位置,作為一項(xiàng)規(guī)則
默認(rèn)情況下,緩沖區(qū)大小是等于一個(gè) fastcgi 緩沖區(qū)大小,允許將其設(shè)置為更少
syntax: fastcgi_cache zone;
default: none
context: http, server, location
設(shè)置緩存在共享內(nèi)存中的名稱. 一塊區(qū)域可以被用于不用的地方.
syntax: fastcgi_cache_key line ;
default: none
context: http, server, location
設(shè)置緩存的 key , 例:
fastcgi_cache_key localhost: 9000 $ request_uri;
語(yǔ)法: fastcgi_cache_methods [GET HEAD POST];
默認(rèn): fastcgi_cache_methods GET HEAD;
環(huán)境: main, http, location
GET / HEAD 語(yǔ)法糖, 也就是. 即使你剛剛設(shè)置,也無(wú)法禁用 GET / HEAD
fastcgi_cache_methods POST;
syntax: fastcgi_cache_min_uses n
default: fastcgi_cache_min_uses 1
context: http, server, location
TODO: Description.
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.
syntax: fastcgi_cache_use_stale [updating|error|timeout|invalid_header|http_500]
default: fastcgi_cache_use_stale off;
context: http, server, location
TODO: Description.
syntax: fastcgi_cache_valid [http_error_code|time]
default: none
context: http, server, location
TODO: Description.
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.
syntax: fastcgi_hide_header name
context: http, server, location
默認(rèn)情況下Nginx 不會(huì)從FastCGI 進(jìn)程里給客戶端發(fā)送"Status" 和"X-Accel-..." 消息頭。這個(gè)指令可以用來(lái)掩飾別的headers 。
如果需要"Status" 和"X-Accel-..." 消息頭,那就需要使用這個(gè)指令讓FastCGI 強(qiáng)制發(fā)送消息頭給客戶端。
syntax: fastcgi_ignore_client_abort on|off
default: fastcgi_ignore_client_abort off
context: http, server, location
這個(gè)指令用來(lái)決定忽略用戶取消的請(qǐng)求。
syntax: fastcgi_intercept_errors on|off
default: fastcgi_intercept_errors off
context: http, server, location
這個(gè)指令用來(lái)決定是否要把客戶端轉(zhuǎn)向4xx和5xx錯(cuò)誤頁(yè),或允許Nginx自動(dòng)指定錯(cuò)誤頁(yè)頁(yè)。
注意:你需要在此明確錯(cuò)誤頁(yè),它才是有用的。Igor 曾說(shuō):“如果沒(méi)有定制的處理機(jī)制,Nginx不會(huì)攔截一個(gè)沒(méi)有缺省頁(yè)的錯(cuò)誤。Nginx 只會(huì)攔截一些小的錯(cuò)誤,放過(guò)其他一些。
syntax: fastcgi_param parameter value
default: none
context: http, server, location
該指令指定的參數(shù),將被傳遞給FastCGI-server。
它可能使用字符串、變量及其它們的組合來(lái)作為參數(shù)值。如果不在此制定參數(shù),它就會(huì)繼承外層設(shè)置;如果在此設(shè)置了參數(shù),將清除外層相關(guān)設(shè)置,僅啟用本層設(shè)置。
下面是一個(gè)例子,對(duì)于PHP來(lái)說(shuō)的最精簡(jiǎn)的必要參數(shù):
fastcgi_param SCRIPT_FILENAME /home/www/scripts/php$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
參數(shù)SCRIPT_FILENAME 是PHP 用來(lái)確定執(zhí)行腳本的名字,而參數(shù)QUERY_STRING 是它的一個(gè)子參數(shù)。
如果要處理POST,那么這三個(gè)附加參數(shù)是必要的:
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
如果PHP 在編譯時(shí)使用了--enable-force-cgi-redirect選項(xiàng),設(shè)置參數(shù)REDIRECT_STATUS 的值為200就是必須的了。
fastcgi_param REDIRECT_STATUS 200;
更多建議: