Rails app with mod_proxy


#1

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


#2

Dont…

have it translated on its way back out…

mod_proxy can do translation both ways.


#3

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?


#4

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.


#5

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-
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
http://yakimaherald.com
509-577-7732
removed_email_address@domain.invalid


#6

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) 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