通过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

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

相关推荐
碳基修炼11 小时前
排查记:本地 devServer 是 http,浏览器却把 302 重定向升级成了 https
前端·http
那年窗外下的雪.18 小时前
第 02 天:Linux 权限、inode、目录项与链接
学习·http
毅炼19 小时前
不写多语言 SDK,怎么让 Python、Go、Node 服务接入注册中心?
java·后端·系统架构·gateway
那年窗外下的雪.19 小时前
AIDC 学习日志|第 27 天|EVPN 多归属收敛时间线与 Leaf2 接管验证
网络协议·学习·http·tcpdump
j7~20 小时前
【Linux】三十八.C++ 手写 HTTP 服务器:裸 socket + fork 多进程,从 HTTP 报文解析到浏览器打开网页
linux·网络·网络协议·学习·http·网络编程
布莱克6053 天前
HTTP 状态码详解:从分类到实战
计算机网络·http·状态码
StevenSurpass3 天前
打印业务彻底解耦:FastPrintAgent 统一 JSON 模型 + FastReport 引擎的设计与落地
mqtt·http·中间件·打印·fastreport
Raas1004 天前
AI网关支持哪些模型?MAI Gateway(魔芋企业级AI网关)功能实测与最佳实践
大数据·人工智能·gateway·mai gateway·企业级产品
Raas1004 天前
MAI Gateway(魔芋企业级AI网关)技术揭秘:AI网关支持DeepSeek吗?从原理到落地
大数据·人工智能·gateway·ai网关·mai gateway·魔芋·企业级产品
小此方4 天前
Linux网络(十二):HTTP短连接与长连接:从Connection机制到Cookie、Session,彻底理解HTTP的无状态
服务器·网络·http