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