Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


    AuthType Basic
    AuthName "My site"
    AuthBasicProvider external
    AuthExternal pwauth
    Require valid-user

    Order deny,allow
    Allow from all

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: - 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/' - 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/' - 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/' - 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/' - 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/' - 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:

How to fix it?


share|improve this question

marked as duplicate by Jenny D, dawud, Katherine Villyard, mdpc, Ward Feb 23 '14 at 0:31

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 1 down vote accepted

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]
share|improve this answer
A lot of changes indeed! Now it works correctly! Thyank you so much. Seems like one needs to read mod_rewrite manual over and over again until there is a solution :) – Zaar Hai Jan 30 '14 at 7:24

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