We have a fairly typical setup: client <-> apache2 (2.2.22) <-> backend (*).

Initially we were using mod_rewrite with the [P] flag in the simplest form:

<VirtualHost *:80>
  RewriteEngine On
  ProxyPreserveHost On
  RewriteRule ^(.*)$ http://localhost:8081$1 [P,L]

However using this setup, even when the clients used keep-alive connections and were sending multiple http requests using one tcp connection to apache, apache was creating a new tcp connection to the backend for reach request.

I decided to try using mod_proxy directly instead:

ProxyPreserveHost On
ProxyPass / http://localhost:8081/

And to my surprise now the tcp connections between apache and the backend are re-used (which was my initial goal).

Why is that? Is there something in mod_rewrite to configure to enable keepalive backend connections?

(*) The backend is actually haproxy <-> multiple app servers, but I don't think it matters here.

3 Answers 3


mod_proxy does connection pooling. mod_rewrite doesn't.

  • Is there a way to configure mod_rewrite to do connection pooling as well? Is it documented anywhere in the docs (I couldn't find anything)?
    – adamw
    Sep 3, 2012 at 15:07
  • Again, mod_rewrite does not do connection pooling. Sep 3, 2012 at 17:31
  • Ok, got it, just wanted to make sure it's not configurable. It should be mentioned in the docs, though :)
    – adamw
    Sep 3, 2012 at 19:56
  • See also my blog with a more detailed explanation of the problem: warski.org/blog/2012/09/…
    – adamw
    Sep 19, 2012 at 17:11
  • It's not about pooling, mod_rewrite uses mod_proxy's "Default Reverse Proxy Worker", which doesn't reuse connections and can't be configured. See mod_proxy docs. Apr 30, 2021 at 8:36

You can use http keep alive even if you do reverse proxy via rewriting, you just need to set keepalive to On via the ProxySet directive like this:

<Proxy "http://backend">
    ProxySet keepalive=On

Source: https://httpd.apache.org/docs/2.4/mod/mod_proxy.html#proxyset

  • You probably mean enablereuse, keepalive is actually TCP-keepalive. The naming is a bit misleading in the context of HTTP. This works anyway, because like this, a new Proxy worker is created and enablereuse is On by default. Otherwise, this is the correct answer. Apr 30, 2021 at 8:39

Using a pair of dummy ProxyPass directives as described in http://www.gossamer-threads.com/lists/apache/users/336740 allows the use of connection pooling with a RewriteRule.

  • 1
    Thanks for the answer Havenless. At ServerFault, we prefer if you quote the most important parts of your links here instead of only posting a link
    – MichelZ
    May 9, 2014 at 11:07
  • 1
    The link is now dead Sep 28, 2020 at 16:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .