Now a days Apache + mod_proxy + mongrel_clusters, Lighttpd + Mongrel cluster and Nginx + mongrel cluster are well known for deploying rails applications.
You can also deploy your rails application with pound(a reverse proxy, load balancer and HTTPS front-end for Web server).
First you need to setup mongrel_clusters for your rails application by issuing ” mongrel_rails cluster::configure -e production -p 8000 -a 127.0.0.1 -N 3 -c ./ ” inside the rails application root directory(on client machine). This will create mongrel_cluster.yml in config directory. You can change parameters in this command, as -p 8000 specifies that mongrel instances will start up on port number starting 8000, -a 127.0.0.1 specifies that mongrel instances will listen to the localhost, -N specifies the number of mongrel instances and -c specifies the rails root directory.
Now you need to install pound(if not installed) by issuing following commands(as root):
- cd /opt/src
- wget http://www.apsis.ch/pound/Pound-2.3.2.tgz
- tar xzpf Pound-2.1.6.tgz
- cd Pound-2.1.6
- make install
This will install pound in /usr/local/sbin/pound. In order to proceed further we need to create pound.cfg(pound configuration file) in /etc/pound/pound.cfg . Below is the content of pound.cfg:
User "pound" Group "pound" ListenHTTP Address 0.0.0.0 Port 80 Service BackEnd Address 127.0.0.1 Port 8000 End BackEnd Address 127.0.0.1 Port 8001 End BackEnd Address 127.0.0.1 Port 8002 End End End
Start mongrel cluster by issuing mongrel_rails cluster::start in you app root directory, start pound by /usr/local/sbin/pound -f /etc/pound/pound.cfg , now you are done. Pound is listening the port 80 and redirect all requests to mongrel instances running on 8000, 8001, 8002.
* Please Note that we have configured pound at port 80, if port 80 is being used by apache or any other application pound will not start. You need to stop any service using port 80, if it is apache then stop apache, change line ‘Listen 80’ to “Listen 8080” and start apache.
In a specific case, when apache is running at some port (let say 8080), you may want to use apache to serve static content of your application, in order to reduce some load from mongrels. In that case use the following:
Its all done. All requests for dynamic content at port 80 will be redirect to mongrel running at 8000, 8001, 8001 and requests for static content will be served by apache running at port 8080.