Deploying A Rails App To Rackspace Cloud Servers On Ubuntu Using Nginx and Unicorn

by dontangg on April 4, 2012

I recently setup a Rails server on Ubuntu using Nginx and Unicorn and a database running on the same server using Postgres. I also used rbenv and ruby-build for ruby. I had to look up a lot of information to get this all working. I just wanted to consolidate everything I did into one place. Hopefully, all this can help someone else.

Here are some links to the different parts of this post:

Here are some resources I used to get everything setup the way I wanted:

I took my approach from many different places and I’ll explain why I did what I did.

Update – I have since watched a few Railscasts that are very well done and explain most of the same concepts. There are several things that he recommends doing that I will definitely do. He is charging money to see those episodes ($9/month), so I would feel a little guilty posting what I learned here.

Why use these technologies?


Originally, I wanted to host my website on Heroku. Heroku is easy, awesome, and really simple. One web dyno is free and it can scale really easily. For the foreseeable future, however, I will have very low traffic and I want it to be as cheap as possible.

My problem with Heroku came when I realized that I needed more than 5MB of database space. The next tier up gives me 20GB and costs $15/month. This is way more space than I need and costs a lot more than I want to pay.

So, I started looking at VPS hosting since I can get a cheap VPS and have more than 5MB of space for my database, plus I can use it to run jobs if I want, etc. I looked at the cheapest offered solutions at Linode, Dreamhhost, MediaTemple, Amazon, and Rackspace. Rackspace beats them all with 256MB of RAM and 10GB Disk for $11/month + $0.18/GB of bandwidth. I highly doubt that I’ll even use 1GB of bandwidth. Plus, if I do need to scale, it will be really easy to do it with Rackspace Cloud Servers.

Web Framework

Honestly, my main reason for doing my site in Rails is because I love Ruby and Rails is fun to work in.

Http Server

My reasons are better stated by others:

Since this is for a low traffic site, I went on the word of others. If I was expecting a lot of traffic, I probably would have done more research and some of my own benchmarks. That said, I do feel pretty confident in this setup even though I didn’t do that. Let’s get started!

Page: 1 2 3 4 5 6


Cool post!

A few comments/thoughts:

1. I still like RVM, and am used to it and see no reason to switch to rbenv. That said, I had trouble (and am still having trouble) with Ubuntu + OpenSSL + Ruby 1.9.2 + RVM. I’m not sure which aspect is to blame here, but all I know is I built this same server on Gentoo a year ago and didn’t have these OpenSSL issues.
2. I like thin over unicorn, as it allows for asynchronous IO. Although, to be fair, I’m not utilizing it much yet, so at this point I don’ think it matters too much what server I use for my Rails app.

I have been working hard on getting this dang Ubuntu box up and running. I think part of my frustration has actually stemmed from selecting the smallest (256mb) size server. It might be an interesting idea to choose a bigger instance at first, then after you’re done installing all the prerequisites, re-size it to a smaller instance and then save an image. I think that’s what I’ll do next time.

I also thing I’ll go back to Gentoo next time, or even (God help me), CentOS.

by Steve on May 7, 2012 at 1:34 am. Reply #

Thanks, I’m about to deploy to rackspace and plan to follow your instructions.

Does rackspace give you information regarding how much memory your instance is using?

by stephen murdoch on June 20, 2012 at 4:19 pm. Reply #

Yes, Rackspace tells you how much space you’re using. I haven’t look hard in the website to find it, but I know you can see it when you ssh into your server. As part of the welcome message, it gives you a bunch of stats like, number of running processes, hard disk usage, ram usage, etc.

I watched Ryan Bates’ Railscast after I posted this and found it very beneficial. I highly recommend it. You can find it here:

by dontangg on June 20, 2012 at 4:42 pm. Reply #

Thanks for the post, i absolutely will try this configuration later, while still on development.
Now i’m also on rackspace’s 256mb Debian 6, RVM + passenger + nginx + mysql.

by Adi Suryadi on July 26, 2012 at 5:59 pm. Reply #

I have a just a few questions. If I set my nginx, and unicorn files to the Rackspace provided IP instead of port 80 I can load the static pages from my rails app If I change it to port 80 and try to go to the rackspace provided IP is just see bad gateway message from nginx, would you be able to give me some guidance?

by nofx1717Jesse on September 19, 2012 at 10:56 am. Reply #

Sorry for the late reply. I just got back from a trip to Disneyland with my family. I don’t consider myself an expert in server setup/maintenance. At this point it would take me a while to remember everything. Part of the reason for this post was for me to be able to remind myself what I did. I don’t think that I can be much help with the time I have. I definitely recommend the Railscasts that I mentioned in the post on setting up a VPS. He does a great job of explaining the details. IMO, the one video itself is well worth the $9 it costs for a membership for a month.

by dontangg on September 28, 2012 at 10:33 pm. Reply #

Awesome post! What version of ubuntu are you running on RackSpace? Is it a 1st gen or next gen cloud server?

by James Stone on November 24, 2012 at 1:19 am. Reply #

I’m glad you liked it! It is a 1st gen cloud server. They hadn’t announced the next gen ones when I started. I’m running Ubuntu 11.10.

by dontangg on November 24, 2012 at 1:29 am. Reply #

Terrific post. Thank you! Got it up and running without issue.

by Bijan on February 19, 2013 at 6:12 pm. Reply #

Leave your comment


Required. Not published.

If you have one.