2

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.

1 Answer 1

0

When using the [P] flag in a RewriteRule to proxy, you would normally be able to use the ProxySet directive to set the options normally configured via ProxyPass.

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:

ProxyPassMatch /\w+/ http://$1.myhostname.com/ keeplive=on

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):

<Proxy *>
    ProxySet keepalive=on
</Proxy>
2
  • I'm pretty sure I already tried the ProxySet approach without much luck. Certainly due to the aforementioned bug. As you said, I can't use the ProxyPass directive due to the different domains.
    – Julien
    Oct 11, 2016 at 13:51
  • You could try my first suggestion if you are just doing user accounts.
    – Unbeliever
    Oct 11, 2016 at 14:22

You must log in to answer this question.

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