Setting timeout for all the ProxyPass mappings in Apache Server mod_proxy directive [closed]
Asked Answered
T

1

16

What I have and works:

I'm using Apache HTTPD 2.2 for proxy requests. I have multiple ProxyPass mappings:

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/

...

This works well.

What I want:

Some of my requests are taking longer, so they timed out giving me a Proxy Error - Reason: Error reading from remote server.

I want to set timeout for all of my requests. Can I do this without having to add timeout=... KeepAlive=On for every ProxyPass mapping?

I currently have something like:

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

Can I tell Apache in some way to add timeout and KeepAlive parameters for all the mappings? Thanks in advance.

Tichonn answered 12/2, 2013 at 9:12 Comment(3)
Off topic. Try serverfault.com.Boletus
I agree with you that it goes better in ServerFault, but there are Apache and mod_proxy related tags, are there not? My question targets the mod_proxy directive settings of Apache 2.2 Server.Tichonn
I know, thank you for that. I managed however to find a solution by my own and I'm adding it here, maybe someone finds it useful.Tichonn
T
33

I've managed to find a solution by my own. You can set the timeout using directly the ProxyTimeout directive of mod_proxy :

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

ProxyTimeout 1200
Tichonn answered 12/2, 2013 at 12:23 Comment(3)
What is that ProxyPreserveHost for ? To setting timeout ProxyTimeout Directive isn't enough !!!! Do we have to specify all these lines to setup ProxyTimeout ?Omegaomelet
Where are these lines added?Yance
The directive ProxyTimeout can be placed in: server config and under virtual host. Initial question was about all of the requests made, which means global scope (server config), thus I would put it to /etc/apache2/mods-available/proxy.conf or familiar file under Apache conf dir, to keep it in order. However, in practice, it can be placed anywhere. I would also wrapped it in <IfModule mod_proxy.c></IfModule> to avoid a failure upon migration or module package removable.Coaster

© 2022 - 2024 — McMap. All rights reserved.