通过route访问Openshift上的HTTP request报错504 Gateway Time-out【已解决】

现象:

数据量过多的时候,HTTP请求大概30秒后会报错

复制代码
<html>

<body>
    <h1>504 Gateway Time-out</h1>
    The server didn't respond in time.
</body>

</html>

解决思路

分析访问链路:

客户端发起请求 -> Haproxy -> Route -> Service -> Pod(nginx)

1.修改haproxy配置

在 HAProxy 配置文件(例如 /etc/haproxy/haproxy.cfg)的前端和后端部分添加或修改以下内容:

cfg 复制代码
defaults
  mode                    http
  log                     global
  option                  dontlognull
  option http-server-close
  option                  redispatch
  retries                 3
  timeout http-request    10s
  timeout queue           1m
  timeout connect         10s
  timeout client          1m
  timeout server          1m
  timeout http-keep-alive 10s
  timeout check           10s
  maxconn                 3000

改成

cfg 复制代码
defaults
  mode                    http
  log                     global
  option                  dontlognull
  option http-server-close
  option                  redispatch
  retries                 3
  timeout http-request    300s
  timeout queue           300s
  timeout connect         300s
  timeout client          300s
  timeout server          300s
  timeout http-keep-alive 300s
  timeout check           300s
  maxconn                 3000

配置完成后重启 HAProxy:

bash 复制代码
sudo systemctl restart haproxy

2.修改路由超时时间

bash 复制代码
oc annotate route <route-name> haproxy.router.openshift.io/timeout=<timeout-value>,如 300s

或者在route yaml加入

yaml 复制代码
annotations:
  haproxy.router.openshift.io/timeout: 600s

3.修改nginx配置

在 Nginx 配置文件(例如 /etc/nginx/nginx.conf 或特定站点配置文件)中添加或修改以下内容:

conf 复制代码
http {
    server {
        ...
        location / {
		    keepalive_timeout   300;
		    fastcgi_connect_timeout 300;
		    #fastcgi连接超时时间,默认60秒
		    fastcgi_send_timeout 300;
		    #nginx 进程向 fastcgi 进程发送请求过程的超时时间,默认值60秒
		    fastcgi_read_timeout 300;
		    proxy_connect_timeout       300;
		    proxy_send_timeout          300;
		    proxy_read_timeout          300;
		    send_timeout                300;
        }
    }
}

配置完成后重启 Nginx:

bash 复制代码
sudo systemctl restart nginx

在此验证,发现问题已经解决!!!

相关推荐
小坏讲微服务1 小时前
使用 Spring Cloud Gateway 实现集群
java·spring boot·分布式·后端·spring cloud·中间件·gateway
没有bug.的程序员1 小时前
Spring Cloud Gateway 路由与过滤器机制
java·开发语言·spring boot·spring·gateway
驯狼小羊羔2 小时前
学习随笔-http和https有何区别
前端·javascript·学习·http·https
草明2 小时前
Chrome HSTS(HTTP Strict Transport Security)
前端·chrome·http
njnu@liyong3 小时前
HTTP-发展史
网络·网络协议·http
0和1的舞者18 小时前
网络通信的奥秘:HTTP详解 (六)
网络·网络协议·计算机网络·http·https·计算机科学与技术
Albert Edison1 天前
【项目设计】基于正倒排索引的Boost搜索引擎
linux·网络·c++·后端·http·搜索引擎
爱编程的鱼1 天前
403 是什么意思?一文读懂 HTTP 状态码 403 及解决方法
网络·网络协议·http
Unstoppable221 天前
八股训练营第 8 天 | TCP连接三次握手的过程?TCP连接四次挥手的过程?HTTP的Keep-Alive是什么?
网络·tcp/ip·http·八股
视觉AI1 天前
HTTP 请求与数据交互全景指南:Request、GET、POST、JSON 及 curl
http·json·交互