I am implementing a reverse http proxy:


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:


I need this to be:


I have implemented the following config in Apache:

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

as per:


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:


Is there something wrong with my config?

  • is this a malfunction limited to devise or is the whole rails site which fails generating correct URLs?
    – 473183469
    Nov 6, 2015 at 10:17
  • I'd be surprised if it was anything to do with Devise. Apache shoudn't care how the Location header is generated. Apache should be be able to look in the Header sent from the destination server and change the subsequent Header sent to the client based on the ProxyPassReverse rule. Nov 6, 2015 at 10:34

1 Answer 1


Figured it out:

ProxyPass "/server1/" "http://server1.example.com/"
ProxyPassReverse "/server1/" "http://proxy.example.com/"
  • 1
    Seemps fragile, this means that if your upstream gives you an absolute uri like: server1.example.com/my/path this won't be rewriten with the correct value which should be proxy.example.com. In your case you're doing two rewrtites on your URI, one the FQDN of the server, proxy / server1 and another on the location, so /users/sign_in to /server1/users/sign_in. It's way easier if you can configure your upstream (server1) to serve your app at the same webroot, /server1
    – Fredi
    Nov 6, 2015 at 14:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .