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

Behind the scenes my app runs like this:

http://myapp.mydomain.com/myapp and
and
https://myapp.mydomain.com/myapp
are Apache 2.2 virtual hosts proxy-balanced to a mongrel cluster
on the same machine.

But I need to make these available here:

https://www.mydomain.com/myapp
and
https://myapp.mydomain.com/myapp
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 =>

HTTPS_PROTOCOL}
map.logout ‘/logout’, :controller => ‘sessions’, :action =>
‘destroy’
map.login ‘/login’, :controller => ‘sessions’, :action =>
‘new’
end

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 https://www.mydomain.com/myapp/login but instead I get
https://myapp.mydomain.com/myapp/login.

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

Thanks,

Sven

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