How do I configure an Amazon EC2 instance as a personal space to serve up whatever Ruby on Rails or WordPress projects I want, with their own domains? As a developer, I’ve found surprisingly little information on how to create your own “bucket” for all your various web-based projects.
Leave a Reply
You must be logged in to post a comment.
It’s surprisingly easy to get started but there are dozens of different ways to go about it. For the sake of giving you relevant resources I’m going to make a few assumptions about your setup and try to paint with broad strokes:
The first thing you’ll want to do is read up on virtual hosts (vhosts). A common pattern is to put virtual hosts’ web roots in subdirectories of /var/www/vhosts/ (e.g. /var/www/vhosts/example.com/), though these can technically live anywhere on the server.
After creating your document roots you’ll give each site each a virtual host file in /etc/apache2/sites-available that looks (at a very high/rudimentary level) something like this:
This tells Apache to listen for requests for http://www.example.com and route them to /var/www/vhosts/example.com. There are a whole mess of Apache vhost configuration options, I’d recommend a Google search for some more specific examples though looking at the
000-default
vhost that comes bundled with Apache on Ubuntu is a good place to start.When you’re ready to activate the vhost you’ll need to enable the virtual host and reload/restart Apache:
Since you want to point different domains to your projects you’ll simply need to create a DNS record (A-records will be the easiest unless you’re dealing with all sorts of shifting IP addresses) and point it to the IP address of your server. Apache will route the domain to the appropriate virtual host.
For Rails projects the web root should be the public/ directory, so your
DocumentRoot
directive will beDocumentRoot /var/www/vhosts/example.com/public
. You’ll also need to be running a Ruby-compatible server for Rails apps, Phusion Passenger, Thin, and Unicorn are all pretty popular.