nginx性能调优之proxy_read_timeout

proxy模块的proxy_read_timeout
syntax: proxy_read_timeout the_time

default: proxy_read_timeout 60

context: http, server, location

This directive sets the read timeout for the response of the proxied server. It determines how long NGINX will wait to get the response to a request. The timeout is established not for entire response, but only between two operations of reading.

In contrast to proxy_connect_timeout, this timeout will catch a server that puts you in it's connection pool but does not respond to you with anything beyond that. Be careful though not to set this too low, as your proxy server might take a longer time to respond to requests on purpose (e.g. when serving you a report page that takes some time to compute). You are able though to have a different setting per location, which enables you to have a higher proxy_read_timeout for the report page's location.

If the proxied server nothing will communicate after this time, then nginx is shut connection.

上面意思是,如果处理请求所需的时间比较长,比如需要加载一个耗时1.7s的内容,proxy_read_timeout 要设置超过这个时间,否则出现504状态码。如果504偶现,怀疑是请求在某些情况下请求耗时超过read时间限制或者后端部分机器read时间设置问题。

$ vim /data/tengine/conf/tengine.conf #data/tengine/为你的tengine安装目录

proxy_connect_timeout           2s;
proxy_read_timeout              5s; #修改为5s

:wq

这里需要注意,修改的是后端机器上的read超时时间,在后端机器之前的proxy,可能也设置了限制,最好也检查下。

上面这些修改只是临时缓解,要从根本上解决问题,需要优化请求链路本身的耗时。

你可能感兴趣的:(nginx)