# Apache proxypass messes up my link\_to's

**URL:** <https://www.ruby-forum.com/t/apache-proxypass-messes-up-my-link-tos/69578>\
**Category:** Rails\
**Created:** [September 21, 2006, 11:29pm UTC](https://www.ruby-forum.com/t/apache-proxypass-messes-up-my-link-tos/69578 "2006-09-21T23:29:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [September 21, 2006, 11:29pm UTC](https://www.ruby-forum.com/t/apache-proxypass-messes-up-my-link-tos/69578/1 "2006-09-21T23:29:29Z")

</div>

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](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](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/](http://myrailsserver:3000/)  
ProxyPass /myapp [http://myrailsserver:3000/](http://myrailsserver:3000/)  
ProxyPassReverse /myapp/ [http://myrailsserver:3000/](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

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [September 22, 2006, 8:28am UTC](https://www.ruby-forum.com/t/apache-proxypass-messes-up-my-link-tos/69578/2 "2006-09-22T08:28:31Z")

</div>

removed\_email\_address@domain.invalid wrote:

> ProxyPass /myapp/ [http://myrailsserver:3000/](http://myrailsserver:3000/)  
> ProxyPass /myapp [http://myrailsserver:3000/](http://myrailsserver:3000/)  
> ProxyPassReverse /myapp/ [http://myrailsserver:3000/](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](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

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [September 22, 2006, 2:55pm UTC](https://www.ruby-forum.com/t/apache-proxypass-messes-up-my-link-tos/69578/3 "2006-09-22T14:55:51Z")

</div>

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/](http://www.napcsweb.com/blog/2006/05/10/reverse-proxy-fix-plugin/)  
for information and and the install.

c.

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [September 22, 2006, 11:42am UTC](https://www.ruby-forum.com/t/apache-proxypass-messes-up-my-link-tos/69578/4 "2006-09-22T11:42:50Z")

</div>

john.h.jenkins@… \<john.h.jenkins@…\> 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](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](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
