在Apache服务器的mod_proxy指令中为所有ProxyPass映射设置超时时间。

15

我拥有并且正常运作:

我正在使用 Apache HTTPD 2.2 进行代理请求。我有多个 ProxyPass 映射:

ProxyRequests On 
<Proxy *>
AddDefaultCharset off
    Order deny,allow
    Allow from all
</Proxy>
ProxyPreserveHost Off

ProxyPass /a http://some_ip/
ProxyPassReverse /a http://some_ip/

ProxyPass /b http://some_other_ip/
ProxyPassReverse /b http://some_other_ip/

...

这个很有效。

我想要的是:

我的某些请求需要更长时间才能完成,因此它们超时了并给出了代理错误 - 原因:从远程服务器读取错误

我想为所有请求设置timeout。是否可以在不必为每个ProxyPass映射添加timeout=... KeepAlive=On的情况下完成?

我目前拥有类似以下内容的东西:

ProxyPass /a http://some_ip/ timeout=1200 KeepAlive=On
ProxyPassReverse /a http://some_ip/

ProxyPass /b http://some_other_ip/ timeout=1200 KeepAlive=On
ProxyPassReverse /b http://some_other_ip/

... and i do this for all my ProxyPass mappings

我能否通过某种方式告诉Apache为所有映射添加timeoutKeepAlive参数?提前致谢。


不是相关的话题,请尝试访问serverfault.com。 - user207421
1
我同意你的看法,这个问题更适合在ServerFault上讨论,但是那里有Apache和mod_proxy相关的标签,不是吗?我的问题是关于Apache 2.2服务器中mod_proxy指令设置的。 - Raul Rene
3
知道了,谢谢你。然而我已经自己找到了解决方案,现在我将其添加在这里,或许对某些人有用。 - Raul Rene
1个回答

31

我已经自己找到了一个解决方案。您可以直接使用mod_proxyProxyTimeout指令来设置超时时间:

ProxyRequests On 
<Proxy *>
    AddDefaultCharset off
    Order deny,allow
    Allow from all
</Proxy>
ProxyPreserveHost Off

ProxyTimeout 1200

ProxyPreserveHost是用来做什么的?设置超时时间时,仅使用ProxyTimeout指令是不够的!!!我们必须指定所有这些行来设置ProxyTimeout吗? - ArunRaj
4
这些行添加在哪里? - user230910
指令 ProxyTimeout 可以放置在:服务器配置虚拟主机下。最初的问题是关于所有请求的,这意味着全局范围(服务器配置),因此我会将其放置在 /etc/apache2/mods-available/proxy.conf 或 Apache conf 目录下的熟悉文件中,以保持有序。然而,在实践中,它可以放置在任何地方。我还会将其包装在 <IfModule mod_proxy.c></IfModule> 中,以避免迁移或模块包可移除时出现故障。 - Ilia

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接