Pages

Thursday, May 13, 2010

hosting rails app with mongrel + apache2 mod proxy

This article will walk through the steps of servings multiple rails application behind one apache2 server. Assuming that you have basics Rails knowledge and apache2 mod_proxy.

Let say you have a site running apache2 :

www.example.com

and you have 2 rails app named app1 and app2 running at a different host behind the same network as the apache2 server:

http://192.168.1.1:3000/app2

http://192.168.1.2:3000/app1

1. Edit the /etc/apache2/apache2.conf file and add the line below:

Include /etc/apache2/sites-enabled/

2. Edit the file /etc/apache2/sites-enabled/proxy and add the line below:

ProxyPass /app1 http://192.168.1.1:3000
ProxyHTMLURLMap http://192.168.1.1:3000 /app1

ProxyPassReverse http://192.168.100.200:3000
SetOutputFilter proxy-html
ProxyHTMLURLMap / /app1/
AddOutputFilterByType application/json text/plain text/xml text/css application/x-javascript


ProxyPass /app1 http://192.168.1.2:3000
ProxyHTMLURLMap http://192.168.1.2:3000 /app2

ProxyPassReverse http://192.168.1.2:3000
SetOutputFilter proxy-html
ProxyHTMLURLMap / /app2/
AddOutputFilterByType application/json text/plain text/xml text/css application/x-javascript


well the configuration is basically kind of straight forward, it will route the request from your main site /app1 to your rails project under http://192.168.1.1:3000

you can now run your "script/server" and see your rails application running at http://www.example.com/app1

be very careful with rails "render :text =>" cause any text will be encoded to html. If you want to use json for example. try

"render :json =>"

-alip

No comments:

Post a Comment