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

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

相关推荐
组合缺一18 小时前
Solon Server 启动模式深度解析:从 0.3MB 内核到 10+ Server 插件
java·websocket·http·solon·server
Seven9720 小时前
别只会背 200 和 404:HTTP 核心知识完整梳理
tcp/ip·http
AOwhisky20 小时前
Ceph系列第五期:Ceph 对象存储(RADOS Gateway)精讲
linux·运维·笔记·ceph·gateway·对象存储
Aaswk20 小时前
计算机网络概述
网络·网络协议·tcp/ip·计算机网络·http·dubbo
艾莉丝努力练剑20 小时前
【Linux网络】Linux 网络编程:传输层TCP(四)
linux·运维·服务器·网络·tcp/ip·http
深邃-21 小时前
【Web安全】-10-网站关键信息收集:目录扫描的概念,工具目录扫描(内含御剑,FindSomething安装链接),网站服务器收集,操作系统判断
运维·服务器·安全·web安全·http·网络安全
XLYcmy1 天前
全链路验证测试系统:一个针对智能代理(Agent)系统全链路能力的自动化验证脚本
分布式·python·http·网络安全·ai·llm·agent
带刺的坐椅1 天前
Solon Server 启动模式深度解析:从 0.3MB 内核到 10+ Server 插件
java·http·solon·jetty·undertow
掉鱼的猫1 天前
Solon Server 启动模式深度解析:从 0.3MB 内核到 10+ Server 插件
java·http
西凉的悲伤2 天前
Spring Cloud Gateway介绍
java·spring cloud·gateway