# Mongrel + mod\_proxy URL issues

**URL:** <https://www.ruby-forum.com/t/mongrel-mod-proxy-url-issues/100084>\
**Category:** Rails\
**Created:** [July 27, 2006, 1:23am UTC](https://www.ruby-forum.com/t/mongrel-mod-proxy-url-issues/100084 "2006-07-27T01:23:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![thekog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3da27b/32.png) [@thekog](https://www.ruby-forum.com/u/thekog)\
**Post date:** [July 27, 2006, 1:23am UTC](https://www.ruby-forum.com/t/mongrel-mod-proxy-url-issues/100084/1 "2006-07-27T01:23:47Z")

</div>

We have a Centos server with a number of virtual hosts, and my rails app  
runs under one of those virtual hosts using mongrel\_rails. The app lives  
in /home/mydomain/railsapp where /home/mydomain/railsapp/public is the  
rails root.

It runs under mongrel on port 8008, so to get to it users invoke the url  
[http://www.mydomain.com:8008/](http://www.mydomain.com:8008/) - all is fine to this point.

Now I have some users whose firewalls forbid these semantics, so I went  
and configured apache (v1.3) to have mod\_proxy in an attempt to get the  
:8008 out of the URLs the user submits.

With a simple rule like:

ProxyPass / [http://mydomain.com:8008/](http://mydomain.com:8008/)  
ProxyPassReverse / [http://mydomain.com:8008/](http://mydomain.com:8008/)

It works beautifully when the user invokes [http://www.mydomain.com](http://www.mydomain.com). I  
believe all my paths within the app are relative to the rails root. Now  
here is the PROBLEM.

I cannot use ‘/’ for the proxy since [mydomain.com](http://mydomain.com) needs to work for the  
website that already predates the rails app, and in fact wants to offer  
it to it’s users. So I changed the mod\_proxy rules in apache to:

ProxyPass /myapp/ [http://mydomain.com:8008/](http://mydomain.com:8008/)  
ProxyPassReverse /myapp/ [http://mydomain.com:8008/](http://mydomain.com:8008/)

I did this in hopes users could specify [http://www.mydomain.com/myapp/](http://www.mydomain.com/myapp/)

Well this works but the problem is that all the links I created using  
the link\_to method do not invoke  
[http://www.mydomain.com/tourney/controller/etc](http://www.mydomain.com/tourney/controller/etc),  
the merely are relative hrefs that look like  
href=“/mycontroller/mymethod/etc”  
and as a result do not go to the proper pages.

How do I fix this? Why is it different when I specify a subdir versus  
just specifying ‘/’ in my proxy? I have tried using:

ActionController::AbstractRequest.relative\_url\_root = “/myapp” and it  
just does not help. I am extremely confused and tired. I can’t help but  
feel I’m getting close. It’s taken the last 2 days to get mod\_proxy  
working. Any help is appreciated.

---

<div class="post-metadata">

**Author:** ![thekog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3da27b/32.png) [@thekog](https://www.ruby-forum.com/u/thekog)\
**Post date:** [July 27, 2006, 11:04am UTC](https://www.ruby-forum.com/t/mongrel-mod-proxy-url-issues/100084/2 "2006-07-27T11:04:14Z")

</div>

Zed-

Thanks for the reply – I’ll be happy to try it, but if I have problems  
how do I get back to the current version? Just do another install?

I’ll give it a shot this afternoon.

---

<div class="post-metadata">

**Author:** ![thekog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3da27b/32.png) [@thekog](https://www.ruby-forum.com/u/thekog)\
**Post date:** [July 27, 2006, 8:39am UTC](https://www.ruby-forum.com/t/mongrel-mod-proxy-url-issues/100084/3 "2006-07-27T08:39:21Z")

</div>

On Thu, 2006-07-27 at 01:23 +0200, Mike K. wrote:

> ActionController::AbstractRequest.relative\_url\_root = “/myapp” and it  
> just does not help. I am extremely confused and tired. I can’t help but  
> feel I’m getting close. It’s taken the last 2 days to get mod\_proxy  
> working. Any help is appreciated.

Try the current mongrel 0.3.13.4 pre-release:

sudo gem install mongrel --source=[http://mongrel.rubyforge.org/releases/](http://mongrel.rubyforge.org/releases/)

And use the --prefix setting. That’ll do it. Let me know how it works  
otherwise. I’ve got bugs in the queue to be fixed next week.

–  
Zed A. Shaw

> **[Zed A. shaw](https://zedshaw.com/)**
>
> Personal essays and writings by Zed A. Shaw.

[http://mongrel.rubyforge.org/](http://mongrel.rubyforge.org/)  
[http://www.railsmachine.com/](http://www.railsmachine.com/) – Need Mongrel support?

---

<div class="post-metadata">

**Author:** ![thekog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3da27b/32.png) [@thekog](https://www.ruby-forum.com/u/thekog)\
**Post date:** [July 27, 2006, 7:29pm UTC](https://www.ruby-forum.com/t/mongrel-mod-proxy-url-issues/100084/4 "2006-07-27T19:29:32Z")

</div>

OK Zed I have the latest installed and everything runs fine as before in  
the basic setup where I just run off [http://www.mydomain.com:8008/](http://www.mydomain.com:8008/)

However I am confused as to how to use the URI. If I set the prefix to  
anything when mongrel starts it says it is listening and available on  
0.0.0.0:refix.

Should I be using my mod\_proxy rules for dereferencing  
[http://www.mydomain.com/myapp](http://www.mydomain.com/myapp) into [http://www.mydomain.com:8008/](http://www.mydomain.com:8008/) and  
still running mongrel on port 8008 as before?

If I set the prefix I cannot get to my app at all – I probably am not  
using it properly. I need some direction.

Thanks in advance,  
Mike

p.s. - pls feel free to communiate directly, I have been writing sys s/w  
for 20+ years.

---

<div class="post-metadata">

**Author:** ![thekog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3da27b/32.png) [@thekog](https://www.ruby-forum.com/u/thekog)\
**Post date:** [July 27, 2006, 3:26pm UTC](https://www.ruby-forum.com/t/mongrel-mod-proxy-url-issues/100084/5 "2006-07-27T15:26:36Z")

</div>

On Thu, 2006-07-27 at 11:04 +0200, Mike K. wrote:

> Zed-
> 
> Thanks for the reply – I’ll be happy to try it, but if I have problems  
> how do I get back to the current version? Just do another install?
> 
> I’ll give it a shot this afternoon.

Yes, you should be able to do:

gem uninstall mongrel

And then tell it to uninstall all versions just to clear everything out.  
Finally, just do:

gem install mongrel

–  
Zed A. Shaw

> **[Zed A. shaw](https://zedshaw.com/)**
>
> Personal essays and writings by Zed A. Shaw.

[http://mongrel.rubyforge.org/](http://mongrel.rubyforge.org/)  
[http://www.railsmachine.com/](http://www.railsmachine.com/) – Need Mongrel support?

---

<div class="post-metadata">

**Author:** ![thekog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3da27b/32.png) [@thekog](https://www.ruby-forum.com/u/thekog)\
**Post date:** [July 27, 2006, 8:34pm UTC](https://www.ruby-forum.com/t/mongrel-mod-proxy-url-issues/100084/6 "2006-07-27T20:34:09Z")

</div>

Zed I mad some progress. I disabled all the mod\_proxy business. I took  
my app which was in /home/mydomain/test with  
railsroot=/home/mydomain/test/public, and copied the whole tree over to  
/home/mydomain/public\_html – so now there is  
/home/mydomain/public\_html/test with the usual rails subdirs under it.

If I start up mongrel\_rails start -prefix /test/public I can reference  
the app by the URL [http://www.mydomain.com/test/public](http://www.mydomain.com/test/public). All my link-to’s  
are fine.

I did find that anywhere in a view where I hand-coded html for an image  
where I said ![](https://www.ruby-forum.com/images/test.gif) did not work. However if I  
recoded it to use \<%= image\_tag etc %\> instead it found the images  
properly.

I have one remaining problem - I use file column for images, and  
everywhere I use image\_tag(url\_for\_file\_column(…)) I am getting the  
prefix twice. That is the images are assigned to be at  
[http://www.mydomain.com/test/public/test/public/classname/images/imagenum](http://www.mydomain.com/test/public/test/public/classname/images/imagenum)  
instead of  
[http://www.mydomain.com/test/public/classname/images/imagenum](http://www.mydomain.com/test/public/classname/images/imagenum)

I also have to confess things look noticeably slower with the prefix.
