欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 新闻 > 国际 > 通过route访问Openshift上的HTTP request报错504 Gateway Time-out【已解决】

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

2025/7/10 7:32:15 来源:https://blog.csdn.net/qq_32789063/article/details/143360240  浏览:    关键词:通过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)的前端和后端部分添加或修改以下内容:

defaultsmode                    httplog                     globaloption                  dontlognulloption http-server-closeoption                  redispatchretries                 3timeout http-request    10stimeout queue           1mtimeout connect         10stimeout client          1mtimeout server          1mtimeout http-keep-alive 10stimeout check           10smaxconn                 3000

改成

defaultsmode                    httplog                     globaloption                  dontlognulloption http-server-closeoption                  redispatchretries                 3timeout http-request    300stimeout queue           300stimeout connect         300stimeout client          300stimeout server          300stimeout http-keep-alive 300stimeout check           300smaxconn                 3000

配置完成后重启 HAProxy:

sudo systemctl restart haproxy

2.修改路由超时时间

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

或者在route yaml加入

annotations:haproxy.router.openshift.io/timeout: 600s

3.修改nginx配置

在 Nginx 配置文件(例如 /etc/nginx/nginx.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:

sudo systemctl restart nginx

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

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com