请教一个 nginx 超时限制问题

2019-11-11 16:04:23 +08:00
 moonsn
proxy_read_timeout 10ms;

如上配置,如果一个 response 由于某些原因,每 9ms 进行了一次传输(由于两次读操作在 timeout 限制内,所以不会超时)。多次传输才传完 response 的话,假如 response 整体 10ms 超时,response 整体是超时的。这个整体的超时要怎么控制?

The timeout is set only between two successive read operations, not for the transmission of the whole response.

附官网指令文档:

Syntax:	proxy_read_timeout time;
Default:	
proxy_read_timeout 60s;
Context:	http, server, location

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.

2423 次点击
所在节点    程序员
9 条回复
Oa
2019-11-11 17:12:54 +08:00
一小时 8 分钟过去了。。。。。
moonsn
2019-11-11 17:21:38 +08:00
@Oa 估计是问题比较偏?
dppd
2019-11-11 19:37:13 +08:00
其实还不太明白你的意思...从 keepalive 和 HTTP1.1 入手?
moonsn
2019-11-11 20:08:33 +08:00
@dppd append 了

我有个 subrequest 请求,用于获取旁路的信息,比如用户认证什么的。

但是我希望能有个超时机制,这样不至于让旁路拖慢了主请求。使用 proxy_read_timeout 并不能真正做到我想要的限制 response 整体超时。
moonsn
2019-11-11 20:15:53 +08:00
@dppd 感谢,我试试 keepalive
eason1874
2019-11-11 20:21:55 +08:00
“多次传输才传完 response 的话,假如 response 整体 10ms 超时,response 整体是超时的。”

估计大家都看不懂你说什么,怀疑自己水平不够,于是进来看一眼又退出了。你可以把 Nginx 所有 _timeout 结尾的配置都看一遍,看哪个适合你。
azh7138m
2019-11-11 21:14:31 +08:00
send_timeout ?
moonsn
2019-11-11 21:17:39 +08:00
@eason1874 嗯,确实描述有问题,append 的需求是否简单明了?
dndx
2019-11-12 01:12:38 +08:00
OpenResty `body_filter_by_lua` 可以根据已经花在处理上的时间终止请求。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/618476

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX