# Rails app with mod\_proxy

**URL:** <https://www.ruby-forum.com/t/rails-app-with-mod-proxy/47628>\
**Category:** Rails\
**Created:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/rails-app-with-mod-proxy/47628 "2005-11-12T12:49:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![flori](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9de053/32.png) [@flori](https://www.ruby-forum.com/u/flori)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/rails-app-with-mod-proxy/47628/1 "2005-11-12T12:49:46Z")

</div>

Hi,

I want to run a rails app behind a mod\_proxied apache web server. So I  
need to tell rails to create urls for the frontend web server instead of  
the hostname:port (localhost:3000 in this case) it really is listening  
on. I haven’t found a way to configure rails to do this.

I have hacked rewrite\_url for a temporary fix like this atm:

module ActionController  
class UrlRewriter  
alias old\_rewrite\_url rewrite\_url

```
 def rewrite_url(path, options)
   url = old_rewrite_url(path, options)
   url.gsub!(/a.do.main:3000/, 'b.do.main')
   url
 end

```

end  
end

But I think it would be useful if rails offered this via a configuration  
option for similar cases. What do you think?

Florian

---

<div class="post-metadata">

**Author:** ![flori](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9de053/32.png) [@flori](https://www.ruby-forum.com/u/flori)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/rails-app-with-mod-proxy/47628/2 "2005-11-12T12:49:47Z")

</div>

Dont…

have it translated on its way back out…

mod\_proxy can do translation both ways.

---

<div class="post-metadata">

**Author:** ![flori](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9de053/32.png) [@flori](https://www.ruby-forum.com/u/flori)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/rails-app-with-mod-proxy/47628/3 "2005-11-12T12:49:47Z")

</div>

Sean T Allen wrote:

> mod\_proxy can do translation both ways.

Hmm, it translates the created links in the html/xml pages? How do I  
configure this?

---

<div class="post-metadata">

**Author:** ![flori](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9de053/32.png) [@flori](https://www.ruby-forum.com/u/flori)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/rails-app-with-mod-proxy/47628/4 "2005-11-12T12:49:48Z")

</div>

Florian F. wrote:

> Sean T Allen wrote:
> 
> > mod\_proxy can do translation both ways.
> 
> Hmm, it translates the created links in the html/xml pages? How do I  
> configure this?
> 
> * * *

No it doesnt do that…

you can have rails create your links without the host information…

which takes care of the in html…

and mod\_proxy can take care of the rest.

---

<div class="post-metadata">

**Author:** ![flori](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9de053/32.png) [@flori](https://www.ruby-forum.com/u/flori)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/rails-app-with-mod-proxy/47628/5 "2005-11-12T12:49:49Z")

</div>

On Nov 10, 2005, at 5:50 AM, Florian F. wrote:

> module ActionController
> 
> But I think it would be useful if rails offered this via a  
> configuration option for similar cases. What do you think?
> 
> Florian  
> \Rails mailing list

Florian-

```
I have a good vhost config that does what you want on my blog. Here

```

is a link:

[http://brainspl.at/articles/2005/11/08/apache-vhost-to-proxy-thru-to-](http://brainspl.at/articles/2005/11/08/apache-vhost-to-proxy-thru-to-)  
lighttpd-on-a-higher-port

That will let you run lighttpd behind apache. Lighty can run on  
whatever port you want but the urls will never show the port number  
this way.

Hope this helps-

-Ezra Z.  
Yakima Herald-Republic  
WebMaster

> **[yakimaherald.com | Yakima, Washington - We Tell Your Stories](https://www.yakimaherald.com/)**

509-577-7732  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![flori](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9de053/32.png) [@flori](https://www.ruby-forum.com/u/flori)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/rails-app-with-mod-proxy/47628/6 "2005-11-12T12:49:49Z")

</div>

Sean T Allen wrote:

> No it doesnt do that…
> 
> you can have rails create your links without the host information…

You mean, I should use relative urls with absolute pathes? Yes, this  
would be possible for the links. The situation is a bit more  
complicated, though.

Actually I am trying to get typo ([typo.leetsoft.com](http://typo.leetsoft.com)) to run from this  
configuration, and they use url\_for heavily. This could be a typo  
problem, but I don’t think so, because rails trys to build the absolute  
urls with the hostnames and fails to do it correctly in this setup. If  
url\_for isn’t intended to build the absolute urls, it shouldn’t try to  
put in the hostnames in the first place. It should be either restricted  
to only create relative urls with absolute pathes, or do it correctly.

In the case of typo it’s necessary to have absolute urls for the rss  
feed creation. It is also necessary to create registrations emails with  
click confirmation. It’s of course possbile to force application  
developers to take care of adding hostnames and ports in front of the  
absolute pathes, but shouldn’t rails make developing apps easier instead  
of luring developers into introducing such errors in their apps?

Florian
