背景:

前端fe js轮询(每隔5s) 一个web接口

php-fpm配置:

pm=static

pm.max_children=128

nginx 配置:

error_page 400 403 404 500 501 502 503 504 505 http://www.baidu.com/search/error.html?tc=test;

fastcgi_connect_timeout 5;
    fastcgi_send_timeout 10; 
    fastcgi_read_timeout 10; 
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;
    fastcgi_intercept_errors on; 
    keepalive_timeout  0;

nginx错误日志( error_log):

谷歌浏览器错误页面:

随着请求的增多,耗时请求增多,当页面耗时超过10s 则返回302 跳转到 http://www.baidu.com/search/error.html?tc=test;

原因分析:

php脚步 执行超过了10s.导致nginx 等待超时send_timeout ,504,然后error_page 返回浏览302 错误页面

502 504 错误可参照本人之前的 502 504 错误的区别

502  nginx发起连接到php-fpm(由于php-fpm队列太小 被拒绝) 或者 php 脚本超时 直接断开于nginx的链接

504 nginx 超时时间太短(且php-fpm队列较大) 请求太多导致

1. send_timeout

syntax: send_timeout the time

default: send_timeout 60

context: http, server, location

Directive assigns response timeout to client. Timeout is established not on entire transfer of answer, but only between two operations of reading, if after this time client will take nothing, then nginx is shutting down the connection.

注意fastcgi_connect_timeout fastcgi_read_timeout fastcgi_send_timeout 类似

proxy_connect_timeout 65s; #连接超时 默认为60秒
proxy_read_timeout 65s; #读取超时 默认为60秒
proxy_send_timeout 65s; #发送超时 默认为60秒

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秒。

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.
定义了从代理服务器读取响应超时。只是在两个连续的读取操作之间设置超时,而不是为整个响应的传输设置超时时间。如果代理服务器在这段时间内不发送任何东西,连接关闭。

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 receive anything within this time, the connection is closed.

设置发送到代理服务器的请求的超时。只是在两个连续的写操作之间设置超时,而不是为整个请求的传输设置超时时间。如果代理服务器在这段时间内没有收到任何东西,连接关闭。

nginx比较强大,可以针对单个域名请求做出单个连接超时的配置.

比如些动态解释和静态解释可以根据业务的需求配置

proxy_connect_timeout :后端服务器连接的超时时间_发起握手等候响应超时时间

proxy_read_timeout:连接成功后_等候后端服务器响应时间_其实已经进入后端的排队之中等候处理(也可以说是后端服务器处理请求的时间)

proxy_send_timeout :后端服务器数据回传时间_就是在规定时间之内后端服务器必须传完所有的数据

server
  {
 listen       80;
 server_name www.qq.cn;
 index index.jsp index.do index.html;
 root  /data/webapp/qqroot;

#limit_conn   crawler  20;

location /(WEB-INF)/ {
  deny all;
 }

location / {
  proxy_pass http://192.168.1.31:8081;
  proxy_connect_timeout 500s;
  proxy_read_timeout 500s;
  proxy_send_timeout 500s;
  proxy_set_header        X-Real-IP $remote_addr;
  proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header        Host $http_host;
 }

location ~* (\.jpg)|(\.gif)|(\.png)|(\.swf)|(\.html)|(\.htm)|(\.exe)|(\.flv)|(\.doc)|(\.rar)|(\.rtf)|(\.bmp)|(\.xls)$
 {
  root /data/webapp/qqroot/;
 }

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
 {
  expires      30d;
 }

}

proxy_connect_timeout

语法: proxy_connect_timeout timeout_in_seconds

上下文: http, server, location

This directive assigns a timeout for the connection to the proxyserver. This is not the time until the server returns the pages, this is the [#proxy_read_timeout proxy_read_timeout] statement. If your proxyserver is up, but hanging (e.g. it does not have enough threads to process your request so it puts you in the pool of connections to deal with later), then this statement will not help as the connection to the server has been made. It is necessary to keep in mind that this time out cannot be more than 75 seconds.

proxy_read_timeout

语法: proxy_read_timeout the_time

默认值: proxy_read_timeout 60

上下文: 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 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 proxyserver 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.

proxy_send_timeout

语法: proxy_send_timeout time_in_seconds

默认值: proxy_send_timeout 60

上下文: http, server, location

This directive assigns timeout with the transfer of request to the proxy server. Time out is established not on entire transfer of request, but only between two operations of record. If after this time the proxy server will not take new data, then nginx is shut the connection

proxy_connect_timeout、proxy_read_timeout、proxy_send_timeout

proxy_connect_timeout  是和后端建立连接的超时时间,记住不要超过 75s 。如果超时,Nginx 的返回码是多少? 504

proxy_read_timeout  是从后端读取数据的超时时间,两次读取操作的时间间隔如果大于这个值,和后端的连接会被关闭。如果一个请求时间时间非常大,要把这个值设大点。如果超时,Nginx 的返回码是多少? 504

proxy_send_timeout  是向后端写数据的超时时间,两次写操作的时间间隔大于这个值,也就是过了这么长时间后端还是没有收到数据(我理解是 根据 TCP ACK 判断),连接会被关闭。如果超时,Nginx 的返回码是多少? 504

nginx send_timeout 超时导致的302 错误相关推荐

  1. SpringBoot连接超时导致的502错误案例

    1.问题描述 内部系统之间通过Nginx来实现路由转发. 但最近发现有一个系统,经常报502错误,每天达到上百次,完全无法忍受. 2. 原因排查 于是进行排查, 发现配置人员把连接超时时间(serve ...

  2. java 502错误,Spring Boot连接超时导致502错误的实战案例

    1.问题描述 内部系统之间通过Nginx来实现路由转发. 但最近发现有一个系统,经常报502错误,每天达到上百次,完全无法忍受. 2. 原因排查 于是进行排查, 发现配置人员把连接超时时间(serve ...

  3. java中502错误原因_Spring Boot连接超时导致502错误的实战案例

    Spring Boot连接超时导致502错误的实战案例,错误,时间,客户端,站长站,原因 Spring Boot连接超时导致502错误的实战案例 易采站长站,站长之家为您整理了Spring Boot连 ...

  4. nginx做反向代理时出现302错误

    现象:nginx在使用非80端口做反向代理时,浏览器访问发现返回302错误 详细现象如下: 浏览器请求登录页: 输入账号密码点击登录: 很明显登录后跳转的地址少了端口号. 原因:proxy.conf文 ...

  5. Nginx出现500 Internal Server Error 错误的解决方案

    Nginx出现500 Internal Server Error 错误的解决方案 Nginx 500错误(Internal Server Error  内部服务器错误):500错误指的是服务器内部错误 ...

  6. nginx 的超时设置

    前言 我们在使用nginx做反向代理的时候,可能会遇到这个场景:后端正常的业务处理时间超过了nginx的超时时间,导致nginx主动返回504.为解决这个问题,我们网上搜索发现可以通过调整这几个参数来 ...

  7. nginx依靠超时时间实现上游负载web服务器重启时不影响访问

    nginx依靠超时时间实现上游负载web服务器重启时不影响访问 本文未配置主从机集群,主从多台集群. nginx.conf(或者外联配置文件)中,位于http{}之内,样例如下: - upstream ...

  8. http 302错误,请求暂时被转移错误,解决办法

    [size=medium][b][color=darkred]http 302错误,请求暂时被转移错误[/color][/b][/size] [b]解决办法:[/b] [b][color=darkbl ...

  9. oracle报609,案例:Oracle报错ORA-609 TNS-12537 TNS-12547 连接超时导致

    天萃荷净 生产数据库alert日志中出现错误信息ORA-609 TNS-12537 TNS-12547,分析原因为数据库inbound connect timeout默认为60导致 1.数据库aler ...

最新文章

  1. 独家 | 使EfficientNet更有效率的三种方法(附链接)
  2. goto是python的保留字吗,基于python goto的正确用法说明
  3. WinForm邮件内容编辑器的简单实现
  4. 对int array进行排序
  5. 人从众!中秋小长假全国铁路预计发送旅客4600万人次
  6. 2014年西安区域赛的几道水题(A. F. K)
  7. 苹果手机传照片到电脑_如何将苹果手机的照片和视频导到电脑上?小白看过来哦...
  8. Linux下安装informix11.5数据库
  9. php中的str replace,PHP字符串替换str_replace()函数4种用法详解
  10. TD-SCDMA迫零块线性均衡
  11. 手把手教你入门微信公众号开发
  12. 一个网站查遍所有英文文章 “会议地点及出版商”(亲测搜了80篇全部有效)
  13. 云计算安全-云服务举例
  14. 【数据科学赛】CAIL 2022 #八赛道 #NLP #文本匹配 #信息抽取
  15. 收藏 | 机器学习分类算法
  16. The key to acquiring proficiency in any task is repetition
  17. win10系统更新后文件丢失的解决办法
  18. Ubuntu下九大最佳绘图程序---kolourpaint4 ubantu已经自带了
  19. oracle设置组合主键,Oracle主键的设置
  20. ts 之 属性的修饰符public、private、protect

热门文章

  1. 大数据是如何影响何改变我们生活的?
  2. mac book 查看mysql版本
  3. http请求头类型详解
  4. WINDOW -- U盘做启动盘重装系统
  5. 一个完整的测试流程包括哪些?测试人员需要做什么?
  6. 如何通过Chrome远程调试Android上的Web页面
  7. excel常用函数公式及技巧搜集3
  8. DEA通讯模块读取从机到PLC的数据如果返回数据有两位或多位怎么办
  9. java使用DOM4j解析XML文件
  10. C++ 字符跑酷#5 游戏制作实录