Over the weekend I moved some of my rails applications to yet another rails deployment option (See my previous posts on deploying rails with apache, mongrel and mod_proxy_balancer [1] or pound, lighttptd and mongrel [2]).
I replaced apache with nginx, a small fast webserver with good proxying and rewriting capabilities. Nginx is extremely fast, a lot easier to configure than apache and uses much less memory. The process was remarkably painless. The steps I took were:
- Install Nginx [3]
- Generate an nginx config file [4] using the nginx_config_generator gem. This gem makes it very easy to configure multiple rails sites.
- Launch Nginx [5]. Nginx also has some cool features where you can reload the config file or upgrade the nginx binary without restarting it.
First Impressions
I’d intended to migrate to nginx for a while now because I’d heard a lot of good things about it. But I held off migrating sites because of lack of documention and the fact that other deployment options were working well for me.
Of all the deployment options I’ve used so far, this was by far the quickest and easiest to get setup. The nginx_config_generator gem automated most of the configuration and made it very easy to configure multiple vhosts. You create a YAML file describing your vhosts and then generate your nginx config file from this. Here is an example YAML description [6].
Related links
- Nginx English Documentation [7]
- Example Nginx config file [8]
- Xen and the art of rails deployment [9] Talk from Railsconf by one of the Engineyard developers.
You can also run php apps under Nginx using fastcgi.
- Nginx With PHP As FastCGI Howto [10]
- Getting Drupal running with Nginx [11]