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

**URL:** <https://www.ruby-forum.com/t/problem-getting-rails-to-emit-the-correct-proxy-domain-in-route-urls/149327>\
**Category:** Rails\
**Created:** [September 23, 2008, 6:19pm UTC](https://www.ruby-forum.com/t/problem-getting-rails-to-emit-the-correct-proxy-domain-in-route-urls/149327 "2008-09-23T18:19:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sven](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e47c2d/32.png) [@sven](https://www.ruby-forum.com/u/sven)\
**Post date:** [September 23, 2008, 6:19pm UTC](https://www.ruby-forum.com/t/problem-getting-rails-to-emit-the-correct-proxy-domain-in-route-urls/149327/1 "2008-09-23T18:19:53Z")

</div>

Behind the scenes my app runs like this:

[http://myapp.mydomain.com/myapp](http://myapp.mydomain.com/myapp) and  
and  
[https://myapp.mydomain.com/myapp](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](https://www.mydomain.com/myapp)  
and  
[https://myapp.mydomain.com/myapp](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](https://www.mydomain.com/myapp/login) but instead I get  
[https://myapp.mydomain.com/myapp/login](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

---

<div class="post-metadata">

**Author:** ![sven](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e47c2d/32.png) [@sven](https://www.ruby-forum.com/u/sven)\
**Post date:** [October 2, 2008, 7:37am UTC](https://www.ruby-forum.com/t/problem-getting-rails-to-emit-the-correct-proxy-domain-in-route-urls/149327/2 "2008-10-02T07:37:03Z")

</div>

Check out this plugin: [GitHub - shuber/proxy: Allows rails applications to respond to multiple hosts/domains and proxied requests](http://github.com/shuber/proxy)
