Use of ProxyPassReverse to change Location response header

Posted on

Use of ProxyPassReverse to change Location response header – Problems with loading a website are often blamed on the Internet connection, but even the most perfectly set up network cannot help if there is no service to reply at your destination. One of the most popular HTTP servers used for this task is Apache2. Much of Apache’s popularity can be attributed to its easy installation and use, but never the less it is possible to run into problems with even the easiest of the software. If you’ve encountered an issue loading your web page, follow these simple troubleshooting methods outlined in this guide to attempt to get your web server back up and working again. Below are some tips in manage your apache2 server when you find problem about apache-2.2, mod-rewrite, http, ruby-on-rails, mod-proxy.

I am implementing a reverse http proxy:

proxy.example.com

This will forward requests to servers based on URI:

proxy.example.com/server1 -> server1.example.com

When a user requests proxy.example.com/server1, server1 sends a programatically generated (Ruby Devise Gem) 302 response with the following “Location” value:

proxy.example.com/users/sign_in

I need this to be:

proxy.example.com/server1/users/sign_in

I have implemented the following config in Apache:

ProxyPass "/server1/" "http://server1.example.com/"
ProxyPassReverse "/server1/" "http://server1.example.com/"

as per:

http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypassreverse

“This directive lets Apache adjust the URL in the Location, Content-Location and URI headers on HTTP redirect responses. This is essential when Apache is used as a reverse proxy (or gateway) to avoid bypassing the reverse proxy because of HTTP redirects on the backend servers which stay behind the reverse proxy.”

But the Location header that is being returned by server1 is still:

proxy.example.com/users/sign_in

Is there something wrong with my config?

thx

Figured it out:

ProxyPass "/server1/" "http://server1.example.com/"
ProxyPassReverse "/server1/" "http://proxy.example.com/"

Leave a Reply

Your email address will not be published. Required fields are marked *