本文介绍 Nginx 的 超时(timeout)配置。分享给大家,具体如下:

Nginx 处理的每个请求均有相应的超时设置。如果做好这些超时时间的限定,判定超时后资源被释放,用来处理其他的请求,以此提升 Nginx 的性能。

keepalive_timeout

HTTP 是一种无状态协议,客户端向服务器发送一个 TCP 请求,服务端响应完毕后断开连接。

如果客户端向服务器发送多个请求,每个请求都要建立各自独立的连接以传输数据。

HTTP 有一个 KeepAlive 模式,它告诉 webserver 在处理完一个请求后保持这个 TCP 连接的打开状态。若接收到来自客户端的其它请求,服务端会利用这个未被关闭的连接,而不需要再建立一个连接。

KeepAlive 在一段时间内保持打开状态,它们会在这段时间内占用资源。占用过多就会影响性能。

Nginx 使用 keepalive_timeout 来指定 KeepAlive 的超时时间(timeout)。指定每个 TCP 连接最多可以保持多长时间。Nginx 的默认值是 75 秒,有些浏览器最多只保持 60 秒,所以可以设定为 60 秒。若将它设置为 0,就禁止了 keepalive 连接。通常 keepalive_timeout 应该比 client_body_timeout(见下文)大。

# 配置段: http, server, location

keepalive_timeout 60s;

client_body_timeout

指定客户端与服务端建立连接后发送 request body 的超时时间。如果客户端在指定时间内没有发送任何内容,Nginx 返回 HTTP 408(Request Timed Out)。

# 配置段: http, server, location

client_body_timeout 20s;

client_header_timeout

客户端向服务端发送一个完整的 request header 的超时时间。如果客户端在指定时间内没有发送一个完整的 request header,Nginx 返回 HTTP 408(Request Timed Out)。

# 配置段: http, server, location

client_header_timeout 10s;

send_timeout

服务端向客户端传输数据的超时时间,根据转发的应用服务可以配置 proxy_send_timeout、uwsgi_send_timeout、fastcgi_send_timeout(见下文)。

# 配置段:http, server, location

send_timeout 30s;

Default:

send_timeout 60s;

Context: http, server, location

Sets a timeout for transmitting a response to the client. The timeout is set only between two successive write operations,

not for the transmission of the whole response. If the client does not receive anything within this time, the connection is closed.

client_header_timeout

接收客户端 header 超时, 默认 60s, 如果 60s 内没有收到完整的 http 包头, 返回 408

Syntax: client_header_timeout time;

Default:

client_header_timeout 60s;

Context: http, server

Defines a timeout for reading client request header. If a client does not transmit the entire header within this time,

the 408 (Request Time-out) error is returned to the client.

client_body_timeout

接收客户端 body 超时, 默认 60s, 如果连续的 60s 内没有收到客户端的 1 个字节, 返回 408

Syntax: client_body_timeout time;

Default:

client_body_timeout 60s;

Context: http, server, location

Defines a timeout for reading client request body. The timeout is set only for a period between two successive read operations, not for the transmission of the whole request body.

If a client does not transmit anything within this time,

the 408 (Request Time-out) error is returned to the client.

lingering_timeout

可以理解为 TCP 连接关闭时的 SO_LINGER 延时设置,默认 5s

Syntax: lingering_timeout time;

Default:

lingering_timeout 5s;

Context: http, server, location

When lingering_close is in effect, this directive specifies the maximum waiting time for more client data to arrive. If data are not received during this time,

the connection is closed. Otherwise, the data are read and ignored, and nginx starts waiting for more data again.

The “wait-read-ignore” cycle is repeated, but no longer than specified by the lingering_time directive.

resolver_timeout

域名解析超时,默认 30s

Syntax: resolver_timeout time;

Default:

resolver_timeout 30s;

Context: http, server, location

Sets a timeout for name resolution, for example:

resolver_timeout 5s;

proxy_connect_timeout

nginx 与 upstream server 的连接超时时间,默认为 60s;根据应用不同可配置 uwsgi_send_timeout/fascgi_send_timeout/proxy_send_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.

proxy_read_timeout

nginx 接收 upstream server 数据超时, 默认 60s, 如果连续的 60s 内没有收到 1 个字节, 连接关闭;根据应用不同可配置 uwsgi_send_timeout/fascgi_send_timeout/proxy_send_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.

proxy_send_timeout

nginx 发送数据至 upstream server 超时, 默认 60s, 如果连续的 60s 内没有发送 1 个字节, 连接关闭;根据应用不同可配置 uwsgi_send_timeout/fascgi_send_timeout/proxy_send_timeout。

Syntax: proxy_send_timeout time;

Default:

proxy_send_timeout 60s;

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 rec

nginx post请求超时_Nginx 的超时 timeout 配置详解相关推荐

  1. log nginx 客户端请求大小_Nginx日志分析和参数详解

    本文档主要介绍Nginx设置日志参数的作用,以及Nginx日志常用分析命令 基本大纲: 1.Nginx日志记录格式的介绍 2.Nginx日志参数详解 3.Web服务流量名词介绍 4.Nginx日志常用 ...

  2. Nginx设置成服务并开机自动启动的配置详解

    Nginx 是一个高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务,接下来通过本文给大家介绍Nginx设置成服务并开机自动启动的配置,需要的朋友可以参考下 在/et ...

  3. Nginx配置详解/代理服务的配置说明

    Nginx配置详解 序言 Nginx是lgor Sysoev为俄罗斯访问量第二的rambler.ru站点设计开发的.从2004年发布至今,凭借开源的力量,已经接近成熟与完善. Nginx功能丰富,可作 ...

  4. Linux中Nginx安装与配置详解及常见问题

    3 Nginx安装 3.1 安装前的准备     1)准备 pcre-8.12.tar.gz.该文件为正则表达式库.让nginx支持rewrite需要安装这个库.     2) 准备 nginx-1. ...

  5. nginx配置多个server_Nginx基本属性配置详解

    . Nginx服务的基本配置 1.1 用于调试进程和定位问题的配置项 是否以守护进程的方式运行nginx # 默认ondaemon on|off; 是否以master/worker方式工作 # 默认o ...

  6. Nginx反向代理配置详解

    Nginx反向代理配置详解 Nginx简单的反向代理配置,包括配置文件中各项参数的的注释,好了,开始! 开始首先安装Nginx 一.建立用户和用户组 1 2 ./usr/sbin/groupadd w ...

  7. 分布式应用Nginx配置详解

    分布式应用Nginx配置详解 Nginx基本介绍 Nginx安装 安装依赖 安装openssl 安装pcre 安装zlib 安装Nginx Nginx负载均衡 负载均衡配置 失败重试配置 Nginx限 ...

  8. 前端必备 Nginx 配置详解

    前端开发者必备的nginx知识 nginx在应用程序中的作用 解决跨域 请求过滤 配置gzip 负载均衡 静态资源服务器 nginx是一个高性能的HTTP和反向代理服务器,也是一个通用的TCP/UDP ...

  9. Nginx配置详解与示例

    Nginx配置详解 #定义Nginx运行的用户和用户组 user www www;#nginx进程数,建议设置为等于CPU总核心数. worker_processes 8;#全局错误日志定义类型,[ ...

最新文章

  1. python程序设计搜题软件_智慧职教APPPython程序设计题库及答案
  2. iview admin npm install报错_聊聊NPM镜像那些险象环生的坑
  3. 2015年微软亚洲研究院的惊艳项目,人工智能抢眼
  4. python2与python3共存_【python】--python2与python3 共存
  5. java泛型 例子_关于 Java 泛型的一些有趣的例子
  6. 一个关于Python字符串格式化输出的练习
  7. MFC框架机制详细论述
  8. android+note2+分辨率,5.5英寸720p屏全新RGB像素排列_三星 GALAXY Note II_手机Android频道-中关村在线...
  9. STM32CubeMx配置H7时钟: Frequency searched for is out of range for this vos range
  10. 不规则炫彩创意渐变海报设计模板素材|带来十足的时尚感
  11. mysql 安装服务 w_MySQL的安装与配置
  12. 跟踪调试易语言静态编译支持库的方法
  13. 两数求和(C语言超简单解法)
  14. 怎么解决Myeclipse导入项目中文乱码?
  15. fatal error C1083: 无法打开包括文件: “SDKDDKVer.h”: No such file or directory
  16. Twitter数据获取
  17. 幼麟棋牌创建房间逻辑分析
  18. web前端(1)——了解什么是前端,以及与后端的关系
  19. Android利用zxing生成二维码,识别二维码,中间填充图片超详细、超简易教程
  20. nvcc fatal : No input files specified; use option --help for more information

热门文章

  1. 孩子春节猛吃零食怎么办?专家支招:先用蔬菜填饱肚子
  2. K8S使用dashboard管理集群
  3. 乱码385b1b926a38153d38957556c0dc55b5
  4. php分享十七:http状态码
  5. B6-简析响应者链条
  6. 企业《DHCP服务器群集》高级配置
  7. 51CTO网站博客改版意见寻求
  8. NSURLCache详解和使用
  9. Spring MVC(三) 数据转换、格式化、校验
  10. ps aux 查看进程