You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Apache反向代理Node服务报AH00957连接被拒返回502错误排查

故障原因

初期连接拒绝错误

  • 系统localhost默认同时解析到IPv4的127.0.0.1和IPv6的::1,Node服务仅监听了IPv4的4006端口,Apache优先走IPv6请求时被拒绝。
  • vhost配置错误开启了正向代理参数ProxyRequests on,还重复加载了已经全局启用的proxy、proxy_http模块,存在配置冲突风险。

后续超时错误

  • Apache代理默认超时阈值较低,无法适配你Node服务中爬虫、GraphQL查询这类耗时较长的业务请求。
  • 代理配置缺少header传递规则,导致Node服务无法正常识别请求,出现长期挂起无响应的情况。
修复方案
    1. 修改Apache vhost配置,调整代理规则:
<VirtualHost IP_ADDRESS:80>
    ServerName api.aDomain.com
    Redirect permanent / https://api.aDomain.com/
</VirtualHost>
<IfModule mod_ssl.c>
    <VirtualHost IP_ADDRESS:443>
        ServerName api.aDomain.com

        ProxyRequests Off
        ProxyPreserveHost On
        RequestHeader set X-Forwarded-Proto "https"
        
        # 超时时间单位为秒,可根据业务需求自行调整
        ProxyPass / http://127.0.0.1:4006/ timeout=600 keepalive=On
        ProxyPassReverse / http://127.0.0.1:4006/

        # SSL证书配置保持不变
        SSLEngine on
        SSLCACertificateFile /etc/ssl/api.aDomain.com/apimini.ca
        SSLCertificateFile /etc/ssl/api.aDomain.com/apimini.crt
        SSLCertificateKeyFile /etc/ssl/api.aDomain.com/apimini.key

        ErrorLog ${APACHE_LOG_DIR}/error_api.aDomain.com.log
        CustomLog ${APACHE_LOG_DIR}/access_api.aDomain.com.log combined

    </VirtualHost>
</IfModule>
    1. 按需调整Node服务监听规则(可选,需要支持IPv6时操作):
      修改Node代码中的监听逻辑,支持IPv4/IPv6双栈访问:
// 监听所有网络接口
await app.listen({ port: 4006, host: '0.0.0.0' })
    1. 验证配置并重启Apache服务:
# 先验证配置语法是否正确
apache2ctl configtest
# 重启服务生效
systemctl restart apache2
    1. 若仍有超时问题,逐一排查Node服务的爬虫逻辑、PostgreSQL数据库连接是否正常,排除业务本身的响应超时问题。

内容的提问来源于stack exchange,提问作者Jamie Hutber

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 18:24:00