Problem getting Rails to emit the correct (proxy) domain in route urls

Behind the scenes my app runs like this: and
are Apache 2.2 virtual hosts proxy-balanced to a mongrel cluster
on the same machine.

But I need to make these available here:
are on a second server using ProxyPass and ProxyPassReverse to
point to the first

Unfortunately the second server is running Apache 2.0 or I’d do the
proxy balancing there. I assure you that getting the proxying, the
subfolder, and various necessary transitions between HTTP and HTTPS
working is collectively no fun at all. But I’m writing about a
particular problem:

In my routes I have

HTTPS_PROTOCOL = (Rails.env.production? || Rails.env.test?) ?

“https” : “http”

map.with_options :protocol => HTTPS_PROTOCOL do
    map.resource :session, :requirements => {:protocol =>

map.logout ‘/logout’, :controller => ‘sessions’, :action =>
map.login ‘/login’, :controller => ‘sessions’, :action =>

In my views I make reference to login_path and logout_path and these
correctly form fully-qualified absolute URLs which include the https://
protocol directive. But they point to the wrong server. I am
supposed to get but instead I get

What do I have to do to get Rails to generate these route urls with
the proxy domain instead of



Check out this plugin: GitHub - shuber/proxy: Allows rails applications to respond to multiple hosts/domains and proxied requests