Apache proxypass messes up my link_to's

Hey all,

Ive got some heavy restrictions on a site I’m building. I have to serve
my rails app from a different machine than my web server. The webserver
must use apache, and I cant muck with its configuration too much,
other than to modify the httpd.conf file a bit. I don’t know much about
Apache, but I found a little gem called proxypass that seemed to get me
a little closer to the final solution. The rails server machine is
completely configurable by me, so that’s the good news.

I used Apache proxypass and proxypassreverse in order to be able to
access my rails machine like so:
http://thewebserver.com/myapp/controller/action/id. This works fine,
except all of my link_to’s and redirect_to’s are now 404s as they point
straight to http://thewebserver.com/controller/action/id.

Am I missing something? I may be misusing proxypass for all I know. I
was hoping some of y’all had come across something like this before.
The bottom of my httpd.conf looks like this:

ProxyPass /myapp/ http://myrailsserver:3000/
ProxyPass /myapp http://myrailsserver:3000/
ProxyPassReverse /myapp/ http://myrailsserver:3000/

I’m using webrick as the http server for rails for now, but plan to
move to mongrel once I get this solved.

Thanks in advance,

John

[email protected] wrote:

ProxyPass /myapp/ http://myrailsserver:3000/
ProxyPass /myapp http://myrailsserver:3000/
ProxyPassReverse /myapp/ http://myrailsserver:3000/

I’m using webrick as the http server for rails for now, but plan to
move to mongrel once I get this solved.

You should put the following line in environment.rb:
ActionController::AbstractRequest.relative_url_root = ‘/myapp’
I once documented this at
http://wiki.rubyonrails.org/rails/pages/HowtoSetupApacheProxyingToLighttpdWithFastCGI.
That wiki entry was written for Lighttpd, but the relative_url_root part
works with webrick too.

Bart

There’s a plugin to solve this problem - works like a charm.

See http://www.napcsweb.com/blog/2006/05/10/reverse-proxy-fix-plugin/
for information and and the install.

c.

[email protected]… <[email protected]…> writes:

I used Apache proxypass and proxypassreverse in order to be able to
access my rails machine like so:
http://thewebserver.com/myapp/controller/action/id. This works fine,
except all of my link_to’s and redirect_to’s are now 404s as they point
straight to http://thewebserver.com/controller/action/id.

Your directory structure should be something like this…

/public_html
/myapp --> /any/path/public
[other live files]

/any/path/app
/any/path/components
[…]
/any/path/public
[…]

I.e. use a symlink to the Rails public directory, which can be anywhere
on the
machine (ideally not in a web-accessible directory)

Then, the rails helpers will all work as you expect, automatically.

Gareth

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs