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,可能也设置了限制,最好也检查下。

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

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值