在nginx的日志記錄中,出現(xiàn)499的狀態(tài)碼有很多種情況,我遇到的一種就是nginx反向代理到一個(gè)永遠(yuǎn)打不開的后端或者這個(gè)后端可以打開,但是你訪問(wèn)的延遲很高,日志記錄就是499,發(fā)送字節(jié)數(shù)是0.
Nginx源碼中關(guān)于499的定義是這樣的:
ngx_string(ngx_http_error_495_page), /* 495, https certificate error */
ngx_string(ngx_http_error_496_page), /* 496, https no certificate */
ngx_string(ngx_http_error_497_page), /* 497, http to https */
ngx_string(ngx_http_error_404_page), /* 498, canceled */
ngx_null_string, /* 499, client has closed connection */
可以看到,最后一行 499 表示客戶端關(guān)閉連接。很有可能是因?yàn)榉?wù)器端處理時(shí)間(等待response的時(shí)間)過(guò)長(zhǎng),客戶端“等不及了”。就給關(guān)閉(close)了。
具體解決辦法:
編輯nginx.conf
增加如下參數(shù):
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
proxy_ignore_client_abort on;
#控制nginx請(qǐng)求后端tomcat超時(shí)使用,配置時(shí)間加長(zhǎng)可以有效解決由于client關(guān)閉服務(wù)導(dǎo)致的 gateway 504;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 32 4k;
proxy_busy_buffers_size 64k;