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

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

相关推荐
nvd118 小时前
LiteLLM 如何使用 Redis:从部署位置到精确响应缓存
redis·缓存·gateway
虎王物联11 小时前
ESP32 HTTP客户端开发实战:TLS加密通信与RESTful API集成方案
http·restful·iphone
小僧景贤14 小时前
嵌入式网络协议 | MQTT、CoAP与HTTP协议深度解析(原理、差异、工程选型、代码实操)
mqtt·http·物联网协议·coap·网络协议选型
CDN36016 小时前
360CDN发布HTTP/3(QUIC)弱网加速方案:实测首屏提速40%,彻底终结移动端接口超时与频繁断连
网络·网络协议·http
一条泥憨鱼1 天前
【从0开始学习计算机网络】| DNS -记录类型详解
计算机网络·http·github·域名·dns·记录
白嫖一茶2 天前
HTTP 状态码总共分为五大类
http
XUEYUAN52122 天前
Cloudflare 防护机制深度剖析与跨境数据采集工程化实践
服务器·网络·网络协议·tcp/ip·http
TlSfoward3 天前
TLS指纹库的数据质量与误判治理 TLSFOWARD TLS指纹库
爬虫·网络协议·http
Raas1003 天前
MAI Gateway (魔芋企业级AI网关)支持哪些模型?AI网关多模型统一接入实战指南
人工智能·安全·gateway·企业级·ai网关
meilindehuzi_a3 天前
React JWT 登录鉴权实战:从无状态 HTTP 到路由守卫、Zustand 与 Axios 拦截器
前端·react.js·http