首页 / NGINX / Nginx超时问题详解
Nginx超时问题详解
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Nginx超时问题详解,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2882字,纯文字阅读大概需要5分钟。
内容图文
![Nginx超时问题详解](/upload/InfoBanner/zyjiaocheng/955/97c3226625ec427fa96f256923caaf56.jpg)
Nginx超时问题分析
Nginx作为一个反向代理中间件,常见的代理流程为:
- 接收客户端请求
- 将请求转发到后端服务器
- 接收后端服务器的响应
- 再将响应转发给客户端
以上四步都可能产生超时,解决Nginx超时问题最关键时要知道是在哪一步超时了,然后再调整响应的参数,不是去一个参数一个参数试
Nginx常见的超时设置
网上很多关于这些超时参数的解释,我发现好多都解释不清楚甚至是错误的,最后发现还是官方文档的解释最为靠谱,大家多查阅官方文档
http://nginx.org/en/docs/
keepalive_timeout
Syntax: keepalive_timeout timeout [header_timeout];
Default: keepalive_timeout 75s;
Context: http, server, location
The first parameter sets a timeout during which a keep-alive client connection will stay open on the server side. The zero value disables keep-alive client connections. The optional second parameter sets a value in the “Keep-Alive: timeout=time” response header field. Two parameters may differ.
第一个参数设置一个超时,在此期间保持活动的客户端连接将在服务器端保持打开状态。 零值禁用保持活动的客户端连接。 可选的第二个参数在“Keep-Alive:timeout = time”响应头字段中设置一个值。 两个参数可能不同。
keepalive_timeout参数是一个请求完成之后还要保持连接多久,不是请求时间多久,目的是保持长连接,减少创建连接过程给系统带来的性能损耗,类似于线程池,数据库连接池。
proxy_connect_timeout
Syntax: proxy_connect_timeout time;
Default: proxy_connect_timeout 60s;
Context: http, server, location
Defines a timeout for establishing a connection with a proxied server. It should be noted that this timeout cannot usually exceed 75 seconds.
定义与代理服务器建立连接的超时。 应该注意,此超时通常不会超过75秒。
这个是建立连接的超时时间,不是连接的超时时间
proxy_read_timeout
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.
定义从代理服务器读取响应的超时时间。超时是对两个连续的读取操作之间的设置,不用于传输整个响应。如果代理服务器在此时间内没有传输任何内容,则连接将关闭。
如果代理服务器在此时间内未返回任何内容,Nginx将返回504
proxy_send_timeout
Syntax: proxy_set_header field value;
Default: proxy_set_header Host $proxy_host;proxy_set_header Connection close;
Context: http, server, location
Sets a timeout for transmitting a request to the proxied server. The timeout is set only between two successive write operations, not for the transmission of the whole request. If the proxied server does not receive anything within this time, the connection is closed.
设置将请求传输到代理服务器的超时时间。 超时是对两个连续的写操作之间的设置,不用于传输整个响应。 如果代理服务器在此时间内未收到任何内容,则关闭连接。
proxy_read_timeout与proxy_send_timeout为Nginx与代理服务间无任何内容响应时的超时间,并不是相应的超时时间
内容总结
以上是互联网集市为您收集整理的Nginx超时问题详解全部内容,希望文章能够帮你解决Nginx超时问题详解所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。