Good day,
I'm using Apache as a reverse proxy for my Tornado app which runs on http://localhost:8090
. I want Apache to proxy everything that arrives to /api/v2 through HTTPS to http://localhost:8090
.
Apache is also takes care of authentication, thus I need to forward the authenticated user name to my Tornado app. Hence using mod_rewrite
.
I've added the following entry to Apache config:
<Location "/api/v2">
ProxyPass http://localhost:8090
# Next four lines are to set X-Forwarded-User
RewriteEngine On
RewriteRule .* - [E=RU:%{LA-U:REMOTE_USER}]
RequestHeader set X-Forwarded-User %{RU}e
SSLRequireSSL
AuthType Basic
AuthName "My site"
AuthBasicProvider external
AuthExternal pwauth
Require valid-user
Order deny,allow
Allow from all
</Location>
This works wonders, except that I see the following error in my Apache log:
Request exceeded the limit of 10 subrequest nesting levels due to probable confguration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
I've enabled the debug log for mod rewrite and I see indeed a strange thing - it looks like the rewrite happens 10 times in loop piling the request onto itself:
172.16.0.150 - admin [29/Jan/2014:19:01:06 +0200] [sm397/sid#7f8452235588][rid#7f840c0093b8/initial] (3) [perdir /api/v2/] applying pattern '.*' to uri 'proxy:http://localhost:8090/'
172.16.0.150 - admin [29/Jan/2014:19:01:06 +0200] [sm397/sid#7f8452235588][rid#7f840c01f638/subreq] (3) [perdir /api/v2/] applying pattern '.*' to uri 'proxy:http://localhost:8090/proxy:http://localhost:8090/'
172.16.0.150 - admin [29/Jan/2014:19:01:06 +0200] [sm397/sid#7f8452235588][rid#7f840c00d6a8/subreq] (3) [perdir /api/v2/] applying pattern '.*' to uri 'proxy:http://localhost:8090/proxy:http://localhost:8090/proxy:http://localhost:8090/'
172.16.0.150 - admin [29/Jan/2014:19:01:06 +0200] [sm397/sid#7f8452235588][rid#7f840c025e08/subreq] (3) [perdir /api/v2/] applying pattern '.*' to uri 'proxy:http://localhost:8090/proxy:http://localhost:8090/proxy:http://localhost:8090/proxy:http://localhost:8090/'
172.16.0.150 - admin [29/Jan/2014:19:01:06 +0200] [sm397/sid#7f8452235588][rid#7f840c029e28/subreq] (3) [perdir /api/v2/] applying pattern '.*' to uri 'proxy:http://localhost:8090/proxy:http://localhost:8090/proxy:http://localhost:8090/proxy:http://localhost:8090/proxy:http://localhost:8090/'
172.16.0.150 - admin [29/Jan/2014:19:01:06 +0200] [sm397/sid#7f8452235588][rid#7f840c02de48/subreq] (3) [perdir /api/v2/] applying pattern '.*' to uri 'proxy:http://localhost:8090/proxy:http://localhost:8090/proxy:http://localhost:8090/proxy:http://localhost:8090/proxy:http://localhost:8090/proxy:http://localhost:8090/'
Full log here: http://pastebin.com/raw.php?i=HqnuFFpQ
How to fix it?
Thanks