nginx上傳文件超過限制大小、響應超時、反向代理請求超時等問題解決


1、文件大小超過限制

錯誤信息:413 Request Entity Too Large

錯誤截圖:

相關配置:

client_max_body_size:

Syntax: client_max_body_size size;
Default:
client_max_body_size 1m;
Context: httpserverlocation

Sets the maximum allowed size of the client request body, specified in the “Content-Length” request header field. If the size in a request exceeds the configured value, the 413 (Request Entity Too Large) error is returned to the client. Please be aware that browsers cannot correctly display this error. Setting size to 0 disables checking of client request body size.

翻譯:設置客戶端請求正文的最大允許大小,在“Content-Length”請求頭部字段中指定。如果請求中的大小超過配置的值,則向客戶端返回413(請求實體太大)錯誤。請注意,瀏覽器無法正確顯示此錯誤。將SIZE設置為0將禁用客戶端請求正文大小檢查。

出處:http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size

 

2、連接超時

錯誤信息:504 Gateway Time-out

錯誤截圖:

 

相關配置:

proxy_read_timeout:

Syntax: proxy_read_timeout time;
Default:
proxy_read_timeout 60s;
Context: httpserverlocation

Defines a timeout for reading a response from the proxied server. The timeout is set only between two successive read operations, not for the transmission of the whole response. If the proxied server does not transmit anything within this time, the connection is closed.

翻譯:定義從代理服務器讀取響應的超時時間超時僅在兩個連續的讀取操作之間設置,而不是針對整個響應的傳輸。如果代理服務器在此時間內沒有傳輸任何內容,則連接將關閉。

出處:http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_read_timeout

注意:一般的請求超時多數都是后端代碼業務處理耗時較長導致,故修改這個配置較多,搞不定再修改下面三個配置

 

fastcgi_connect_timeout:

Syntax: fastcgi_connect_timeout time;
Default:
fastcgi_connect_timeout 60s;
Context: httpserverlocation

Defines a timeout for establishing a connection with a FastCGI server. It should be noted that this timeout cannot usually exceed 75 seconds.

翻譯:定義與FastCGI服務器建立連接的超時時間。應該注意,此超時通常不能超過75秒。

出處:http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_connect_timeout

 

fastcgi_send_timeout:

Syntax: fastcgi_send_timeout time;
Default:
fastcgi_send_timeout 60s;
Context: httpserverlocation

Sets a timeout for transmitting a request to the FastCGI server. The timeout is set only between two successive write operations, not for the transmission of the whole request. If the FastCGI server does not receive anything within this time, the connection is closed.

翻譯:設置向FastCGI服務器傳輸請求的超時時間。超時僅在兩個連續的寫入操作之間設置,而不是針對整個請求的傳輸。如果FastCGI服務器在此時間內未收到任何內容,則連接將關閉。

出處:http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_send_timeout

 

fastcgi_read_timeout:

Syntax: fastcgi_read_timeout time;
Default:
fastcgi_read_timeout 60s;
Context: httpserverlocation

Defines a timeout for reading a response from the FastCGI server. The timeout is set only between two successive read operations, not for the transmission of the whole response. If the FastCGI server does not transmit anything within this time, the connection is closed.

翻譯:定義從FastCGI服務器讀取響應的超時時間。超時僅在兩個連續的讀取操作之間設置,而不是針對整個響應的傳輸。如果FastCGI服務器在此時間內沒有傳輸任何內容,則連接將關閉。

出處:http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_read_timeout

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM