2

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

Zaar Hai
  • 447
  • 5
  • 12

1 Answers1

3

That's very strange, as there shouldn't be anything causing the appending on the subrequests.

Let's see if anything changes when that rule isn't applied to the insane subrequests by adding an NS flag:

RewriteRule .* - [E=RU:%{LA-U:REMOTE_USER},NS]
Shane Madden
  • 112,982
  • 12
  • 174
  • 248
  • A lot of changes indeed! Now it works correctly! Thyank you so much. http://pastebin.com/raw.php?i=bTQ6rPUB Seems like one needs to read mod_rewrite manual over and over again until there is a solution :) – Zaar Hai Jan 30 '14 at 07:24