Deployment Recipe

It is important to remember to split up the web server and the app server. We can do this by setting up NGINX as a front end reverse proxy and using Unicorn for serving up the HTTP/S server.

For the stack I use Ubuntu 10.10 with 4 terabytes in a RAID 5, making an effective 3 terabytes. NGINX, Unicorn and Rails run on top of this. If I were getting 2 - 300 requests per minute we would probably need some kind of process monitoring framework such as God or monit. It is also important to host your assets, javascripts, stylesheets, images, on a server different from the one you run your application on. A good solution for this is Amazon S3 or Slicehost. This is per Yahoo’s list of best practices. Key issues are always going to be scalability, security and speed.

 1 worker_processes 4
 2 
 3 working_directory "/var/www/ellisberner/"
 4 
 5 listen "/var/run/unicorn.sock", :backlog => 2048
 6 
 7 timeout 30
 8 
 9 pid "/var/run/unicorn.pid"
10 
11 stdout_path "/var/log/unicorn.log"

This is the standard NGINX config that comes with the Ubuntu package. You should set the workers to the number of cores on your processor. In addition, it is important to have the master worker is running as a privilaged user and the slaves are running as www-data.

 1 upstream unicorn {
 2     server unix:/var/run/unicorn.sock fail_timeout=0;
 3 }
 4 
 5 server {
 6   listen 80;
 7   server_name ellisberner.com;
 8   root /var/www/ellisberner/public;
 9   access_log /var/log/nginx/ellisberner.access.log;
10 
11   location / {
12     try_files $uri @unicorn;
13   }
14 
15   location @unicorn {
16     proxy_pass http://unicorn;
17     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
18     proxy_set_header Host $host;
19     proxy_redirect off;
20   }
21 }