【问题标题】:Proxy timeout with ReWriteRule使用 ReWriteRule 的代理超时
【发布时间】:2025-12-02 13:15:02
【问题描述】:

使用 Apache 2.4 通过 ReWriteRule (mod_rewrite) 进行代理时,无法控制超时。

<VirtualHost "*:443">
  ServerName xxxx
  Use ssl
  RewriteEngine On
  RewriteRule (.*/wms|/openlayers3/.*) http://localhost:8080$1 [P,L]
  RewriteRule .* [F]
</VirtualHost>

我尝试过没有成功:

  • Timeout 400
  • ProxyTimeout 400
  • 代理集
<Proxy "http://localhost:8080/">
  ProxySet connectiontimeout=100 timeout=400
</Proxy>
  • ProxyPass "/" "http://localhost:8080" connectiontimeout=100 timeout=400

无论我使用上述哪个指令,超时始终为 1 分钟。

【问题讨论】:

  • 您能否在某些上下文中显示您遇到的超时的日志条目?

标签: apache proxy timeout


【解决方案1】:

这个超时时间可以控制only globally。将httpd.conf 中的全局Timeout 设置更改为您的首选值:

#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 400

可能更好的方法是使用 nginx:

server {
    listen       443;
    server_name  xxxx;
    # ... ssl setup ...

    location ~* /wms$ {
        proxy_pass http://localhost:8080;
        proxy_read_timeout 400;
    }

    location /openlayers3/ {
        proxy_pass http://localhost:8080;
        proxy_read_timeout 400;
    }

    location / {
        return 403;
    }
}

附加到 nginx 文档的链接,以便您了解此 sn-p 中发生的情况:

对于我的 sn-p 中缺少的 SSL 配置,另请阅读 the documentation

【讨论】:

  • 我的 Apache 配置文件中没有全局 Timeout,除了我放置的那个。它不被尊重。
  • @david.perez 应该在那里:httpd.apache.org/docs/2.4/mod/core.html#timeout
  • @david.perez 但我真的建议只使用 Nginx。它更强大、更可靠、速度更快,而且您可以按照自己的方式轻松配置。
  • 现在我有时间测试一下nginx,它比apache运行得更好,语法看起来更简单,谢谢。