I have an Apache httpd used as a SSL reverse proxy frontend for a lot of backends.
I compute the name of the backend from the path given by the user.
e.g: https://myhostname.com/myaccount
translates to http://myaccount.myhostname.com
For this I use a RewriteMap
and RewriteRule
with [P]
flag on. Everything works fine.
However I now need a persistent connection between the reverse proxy and the backend. I am well aware that keep-alive doesn't work with RewriteRule
's [P]
(http://httpd.apache.org/docs/current/en/rewrite/flags.html#flag_p – performance warning) therefore I tried to use ProxyPass
and environment variable interpolation to do the work.
I got a RewriteRule
that don't do nothing except saving the map result into an environment variable and then call the ProxyPass
using this variable.
RewriteMap mymap prg:/path/to/my/map
RewriteCond %{REQUEST_URI} ^/([^/]+)/?.*$
RewriteCond ${mymap:%1} ^http://([^/]+/)$
RewriteRule ^/([^/]+)/?$ - [L,E=original:$1,E=rewritten:%1]
ProxyPassInterpolateEnv On
ProxyPassReverse /${original}/ http://${rewritten} interpolate
This result in the same behaviour as RewriteRule
with [P]
: the proxying is ok but don't uses http keep-alive.
I tried this with a hard-coded hostname instead of using ${rewritten}
(but keeping the ${original}
) and observed that it's the part that make Apache creating new connection instead of reusing an existing one.
This bug: https://issues.apache.org/bugzilla/show_bug.cgi?id=43308 is raising the same issue and propose a patch that may solve my problem.
However, I wanted to know if anyone had an idea to solve this in a different/better way.
Best Answer
When using the [P] flag in a
RewriteRule
to proxy, you would normally be able to use theProxySet
directive to set the options normally configured viaProxyPass
.But in this case you do not have a specific proxy URL to configure. If you are only proxying user accounts, you could do something like:
Although from your example it seems it's possible different domains are in use (hence the use of a
RewriteMap
).Alternatively, another thought that just occurred, it might work to use the following (untested):