# Deploying rails as a sub-url

**URL:** <https://www.ruby-forum.com/t/deploying-rails-as-a-sub-url/91274>\
**Category:** Rails\
**Created:** [April 6, 2007, 5:56am UTC](https://www.ruby-forum.com/t/deploying-rails-as-a-sub-url/91274 "2007-04-06T05:56:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![msoulier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/97f17d/32.png) [@msoulier](https://www.ruby-forum.com/u/msoulier)\
**Post date:** [April 6, 2007, 5:56am UTC](https://www.ruby-forum.com/t/deploying-rails-as-a-sub-url/91274/1 "2007-04-06T05:56:20Z")

</div>

Hello,

I want to deploy a rails app as a sub-url to an existing site.

So, I’m using ProxyPass in apache to proxy urls for /foo to localhost  
on port  
10000, where mongrel is listening.

Unfortunately, the helper functions in Rails like link\_to seem to  
insist on  
providing absolute urls (ie. /admin). That will break with this  
scheme, since  
the /foo in the URL won’t be maintained.

What is recommended for a deployment like this?

Thanks,  
Mike

---

<div class="post-metadata">

**Author:** ![msoulier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/97f17d/32.png) [@msoulier](https://www.ruby-forum.com/u/msoulier)\
**Post date:** [April 6, 2007, 6:42am UTC](https://www.ruby-forum.com/t/deploying-rails-as-a-sub-url/91274/2 "2007-04-06T06:42:23Z")

</div>

msoulier wrote:

> providing absolute urls (ie. /admin). That will break with this  
> scheme, since  
> the /foo in the URL won’t be maintained.
> 
> What is recommended for a deployment like this?
> 
> Thanks,  
> Mike

You can use --prefix with Mongrel to specify the subdirectory you want  
to run Rails under. E.g.:

mongrel\_rails start -d -p 10000   
-a 127.0.0.1   
-e production   
–prefix /foo

–  
Michael W.

---

<div class="post-metadata">

**Author:** ![msoulier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/97f17d/32.png) [@msoulier](https://www.ruby-forum.com/u/msoulier)\
**Post date:** [April 6, 2007, 7:18am UTC](https://www.ruby-forum.com/t/deploying-rails-as-a-sub-url/91274/3 "2007-04-06T07:18:25Z")

</div>

On Apr 6, 12:40 am, Michael W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> You can use --prefix with Mongrel to specify the subdirectory you want  
> to run Rails under. E.g.:
> 
> mongrel\_rails start -d -p 10000   
> -a 127.0.0.1   
> -e production   
> –prefix /foo

Cool, that works! I had a partially working solution by updating  
routing with the prefix, but that broke access to the public  
directory.

Thanks!

Mike

---

<div class="post-metadata">

**Author:** ![msoulier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/97f17d/32.png) [@msoulier](https://www.ruby-forum.com/u/msoulier)\
**Post date:** [April 6, 2007, 2:20pm UTC](https://www.ruby-forum.com/t/deploying-rails-as-a-sub-url/91274/4 "2007-04-06T14:20:21Z")

</div>

Mike, any chance you could post the relevant code from your httpd.conf  
file?

I’ve been stumbling around, trying to figure this out, for a while now,  
and I’ve yet to get multiple sites working on one box, without having  
work done on DNS tables (which is not a possibility in this case).

With a lot of help, I eventually got RoR working for a single site  
([OSX apache2 final-stage setup hints? - Rails - Ruby-Forum](http://www.ruby-forum.com/topic/100239#216736)) using ProxyPass.

However, this ProxyPass method seems to be the wrong approach for  
multiple sites on one box  
([Multiple virtual host? - Rails - Ruby-Forum](http://www.ruby-forum.com/topic/103505#229200)) since it demands the  
changing of DNS tables, which I lack permission to do. [Commercial  
hosting is not a solution for me.]

Dan.

---

<div class="post-metadata">

**Author:** ![msoulier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/97f17d/32.png) [@msoulier](https://www.ruby-forum.com/u/msoulier)\
**Post date:** [April 6, 2007, 2:41pm UTC](https://www.ruby-forum.com/t/deploying-rails-as-a-sub-url/91274/5 "2007-04-06T14:41:13Z")

</div>

Dan K. wrote:

> However, this ProxyPass method seems to be the wrong approach for  
> multiple sites on one box  
> ([Multiple virtual host? - Rails - Ruby-Forum](http://www.ruby-forum.com/topic/103505#229200)) since it demands the  
> changing of DNS tables, which I lack permission to do. [Commercial  
> hosting is not a solution for me.]

What’s the problem? In httpd.conf you just need something like this:

ProxyPass /site1 [http://localhost:9000/site1](http://localhost:9000/site1)  
ProxyPassReverse /site1 [http://locahost:9000/site1](http://locahost:9000/site1)

ProxyPass /site2 [http://localhost:9001/site2](http://localhost:9001/site2)  
ProxyPassReverse /site2 [http://locahost:9001/site2](http://locahost:9001/site2)

And to launch each Mongrel you need something like (run from inside each  
app directory):

mongrel\_rails start -d -p 9000   
-a 127.0.0.1   
-e production   
–prefix /site1 \

mongrel\_rails start -d -p 9001   
-a 127.0.0.1   
-e production   
–prefix /site2 \

–  
Michael W.

---

<div class="post-metadata">

**Author:** ![msoulier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/97f17d/32.png) [@msoulier](https://www.ruby-forum.com/u/msoulier)\
**Post date:** [April 10, 2007, 1:48pm UTC](https://www.ruby-forum.com/t/deploying-rails-as-a-sub-url/91274/6 "2007-04-10T13:48:19Z")

</div>

The problem is that the images don’t show up, if I do as above.

---

<div class="post-metadata">

**Author:** ![msoulier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/97f17d/32.png) [@msoulier](https://www.ruby-forum.com/u/msoulier)\
**Post date:** [April 6, 2007, 5:01pm UTC](https://www.ruby-forum.com/t/deploying-rails-as-a-sub-url/91274/7 "2007-04-06T17:01:34Z")

</div>

On Apr 6, 8:20 am, Dan K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Mike, any chance you could post the relevant code from your httpd.conf  
> file?

It’s just

ProxyPass /foobar [http://127.0.0.1:10000/foobar](http://127.0.0.1:10000/foobar)  
ProxyPassReverse /foobar [http://127.0.0.1:10000/foobar](http://127.0.0.1:10000/foobar)

Unfortunately it’s not enough, since proxypass only fixes http headers  
and not page contents. The link\_to function and it’s brothers all seem  
to want to use absolute urls instead of relative ones, a terrible  
practice. I tried turning off that behaviour in the default html  
options but it didn’t seem to help.

In the end I used the mongrel option suggested and it’s working great.  
Still, I find it sad that Rails suffers from the same broken  
assumptions about deployment as jakarta-tomcat.

> changing of DNS tables, which I lack permission to do. [Commercial  
> hosting is not a solution for me.]

It now works for me with a combination of proxypass, and mongrel’s –  
prefix option. Should work for you.

Mike
