Directives
fastcgi_bind
fastcgi_buffer_size
fastcgi_buffering
fastcgi_buffers
fastcgi_busy_buffers_size
fastcgi_cache
fastcgi_cache_background_update
fastcgi_cache_bypass
fastcgi_cache_key
fastcgi_cache_lock
fastcgi_cache_lock_age
fastcgi_cache_lock_timeout
fastcgi_cache_max_range_offset
fastcgi_cache_methods
fastcgi_cache_min_uses
fastcgi_cache_path
fastcgi_cache_purge
fastcgi_cache_revalidate
fastcgi_cache_use_stale
fastcgi_cache_valid
fastcgi_catch_stderr
fastcgi_connect_timeout
fastcgi_force_ranges
fastcgi_hide_header
fastcgi_ignore_client_abort
fastcgi_ignore_headers
fastcgi_index
fastcgi_intercept_errors
fastcgi_keep_conn
fastcgi_limit_rate
fastcgi_max_temp_file_size
fastcgi_next_upstream
fastcgi_next_upstream_timeout
fastcgi_next_upstream_tries
fastcgi_no_cache
fastcgi_param
fastcgi_pass
fastcgi_pass_header
fastcgi_pass_request_body
fastcgi_pass_request_headers
fastcgi_read_timeout
fastcgi_request_buffering
fastcgi_send_lowat
fastcgi_send_timeout
fastcgi_socket_keepalive
fastcgi_split_path_info
fastcgi_store
fastcgi_store_access
fastcgi_temp_file_write_size
fastcgi_temp_path
Parameters Passed to a FastCGI Server
Embedded Variables
fastcgi_buffer 相關(guān):
location ~ \.php$ {
fastcgi_pass fpm;
fastcgi_buffer_size 4k;
fastcgi_buffers 8 4k;
fastcgi_buffering on; # 開(kāi)啟 buffer
fastcgi_max_temp_file_size 1m;
fastcgi_temp_path /var/log/nginx/fastcgi.temp 1;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
fastcgi_buffer_size 定義讀取 fastcgi 應(yīng)答第一部分需要多大緩沖區(qū),該值表示使用1個(gè)4kb的緩沖區(qū)讀取應(yīng)答第
一部分(應(yīng)答頭),可以設(shè)置為 fastcgi_buffers 選項(xiàng)緩沖區(qū)大小。
所以 buffer 一共是 8 * 4k + 4k 大小。超出部分將會(huì)用臨時(shí)文件存儲(chǔ),請(qǐng)求結(jié)束刪除。
client_body_buffer_size 1024k;
client_max_body_size 2050m;
這是針對(duì)客戶端設(shè)置的 buffer 。
fastcgi_cache 相關(guān):
location ~ \.php$ {
#fastcgi_pass fpm;
#fastcgi_buffer_size 4k;
#fastcgi_buffers 8 4k;
#fastcgi_buffering on;
#fastcgi_max_temp_file_size 1m;
#fastcgi_temp_path /var/log/nginx/fastcgi.temp 1;
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#include fastcgi_params;
# cache :
fastcgi_cache zzz;
fastcgi_cache_min_uses 1;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
fastcgi_cache_key $request_uri;
fastcgi_cache_valid 200 1m;
add_header X-Cache $upstream_cache_status;
}
fastcgi_cache_path 指定緩存路徑,緩存內(nèi)容:
$ cat nginx/log/fastcgi.cache/1/af/e251273eb74a8ee3f661a7af00915af1
,z0b?????????y0b??"oa?
KEY: /index.php
=Content-type: text/html; charset=UTF-8
2022-03-15 19:35:12%
fastcgi_hide_header Author; 隱藏某些 header 。
fastcgi_ignore_client_abort on;
Determines whether the connection with a FastCGI server should be closed when a client closes the connection without waiting for a response.
fastcgi_intercept_errors off;
response status >= 300 將會(huì)交給 error_page 指令,當(dāng)做錯(cuò)誤處理。
fastcgi_keep_conn on;
建議開(kāi)啟,即 keepalive 。
fastcgi_next_upstream error | timeout | invalid_header | http_500 | http_503 | http_403 | http_404 | http_429 | non_idempotent | off ...;
指示是否交個(gè)下一個(gè)上游,即判斷本次 fastcgi 請(qǐng)求是否失?。╱nsuccessful attempts )。
常見(jiàn)配置有 error ,timeout 超時(shí),http_5xx 狀態(tài)碼,non_idempotent 非POST請(qǐng)求,off 禁用,即全部視為成功。
fastcgi_next_upstream_tries 最大嘗試次數(shù)。
fastcgi_no_cache string;
至少一個(gè)非空非0,就不cache。示例:
fastcgi_no_cache $cookie_nocache $arg_nocache$arg_comment; fastcgi_no_cache $http_pragma $http_authorization;
特別的,對(duì)于 php :
The following example shows the minimum required settings for PHP:
fastcgi_param SCRIPT_FILENAME /home/www/scripts/php$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
The SCRIPT_FILENAME parameter is used in PHP for determining the script name, and the QUERY_STRING parameter is used to pass request parameters.
For scripts that process POST requests, the following three parameters are also required:
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length
fastcgi_pass_request_body,fastcgi_pass_request_headers 控制是否把客戶端的 body,header 傳給 fastcgi server ,一般不使用。
3個(gè) timeout :
fastcgi_connect_timeout 10s;
fastcgi_read_timeout 10s;
fastcgi_send_timeout 10s;
fastcgi_split_path_info 示例:
location ~ ^(.+\.php)(.*)$ {
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME /path/to/php$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
for the “
/show.php/article/0001” request, theSCRIPT_FILENAMEparameter will be equal to “/path/to/php/show.php”, and thePATH_INFOparameter will be equal to “/article/0001”.