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.


mod_proxy does connection pooling. mod_rewrite doesn't.

| improve this answer | |
  • 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 '12 at 15:07
  • Again, mod_rewrite does not do connection pooling. – Ansgar Wiechers Sep 3 '12 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 '12 at 19:56
  • See also my blog with a more detailed explanation of the problem: warski.org/blog/2012/09/… – adamw Sep 19 '12 at 17:11

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.

| improve this answer | |
  • 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 '14 at 11:07

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.