I have set up a redirect in my Apache virtual host serving several subdomains - call them a.example.com and b.example.com - serving a ruby on rails app.

On my virtualhost config file I have this rule:

rewriteEngine on
rewriteRule proxy/(.+)$ http://news.example.com/$1 [P]

The idea is that I can do http://a.example.com/proxy/news/a and get the contents of http://news.example.com/news/a, but within the same subdomain, so ajax doesn't think my ajax requests are cross-domain - more info on this SO question.

The problem is that while it works just fine in my staging environment, it does not in production!

Both servers are Ubuntu server 10.04 . Apache came from the standard ubuntu repos, using apt-get install.

I have made a diff of the whole /etc/apache2/ dir and the only difference is the server name.

If I change the last option to [L], I get a redirect, so this makes me think that mod_rewrite is working. It just doesn't talk with mod_proxy.

By looking at the logs (/var/log/apache2 and the rails log), it seems like the rewrite rule in production is simply being ignored - the logs are exactly the same as if it wasn't there.

How can I debug this? Can I force Apache to give me more information about why this particular rule isn't enforced when I access /proxy?

  • 4
    What does your RewriteLog show you? – larsks Feb 28 '12 at 14:09
  • 1
    Is mod_proxy loaded? It's needed for the [P] flag. – Shane Madden Feb 28 '12 at 16:26
  • @larks: I didn't know about that log! I'm browsing that. – egarcia Feb 28 '12 at 16:50
  • @ShaneMadden yes, mod_proxy is loaded. – egarcia Feb 28 '12 at 16:50

After browsing RewriteLog as larsks suggested, we have realized that Apache was indeed doing the redirects - the problem was somewhere else.

In fact, it was the module we where using to handle ruby - Phusion Passenger.

We had one of those "OMG the server is down!" moments and we tried setting up the PassengerHighPerformance variable to on.

Unfortunately, this setting basically means "ignore mod_rewrite" :)

Now we have tuned it out a bit - it's on in all the locations, except when they begin by /proxy:

PassengerHighPerformance On
<location /proxy>
  PassengerHighPerformance Off

Once we added that configuration option to our virtualhost config file, things started working again!

If you come here via google and found this useful, please upvote Larsks' comment on the OP. His comment was what put us on the right track.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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