Deploying a Rails application with Lighttpd
An alternate method of deploying a Rails application is with Lighttpd. This article assumes that you have a Rails application (whether it's your own, or downloaded elsewhere) already installed and configured. If you haven't, please see the following article:
Getting a Lighttpd port
Lighttpd runs on a port and we need to track these in order to prevent customers from stepping on each other's toes. See the ports on how to pick a port from the range pre-assigned for your account.
Setting up and Configuring Lighttpd
The first thing we need to do is get your account setup for Lighttpd by creating a few directories and uploading some files.
- Make sure you have a port for Lighttpd, because you'll need it in the following steps. If you don't, you'll need to file a support ticket and ask for one
- Download the following file to your computer: lighttpd.conf
- Open lighttpd.conf in a text editor of your choice and replace USERNAME with your Joyent account user name
- Also, replace PORTNUMBER with the port number you were previously assigned
- Replace
APPNAMEwith the short name for your Rails application (e.g., typo). - Now, edit the following line:
$HTTP["host"] =~ "(www\.)?YOURDOMAIN\.com" {So that it contains the domain for your Rails application (replace YOURDOMAIN with the name of your domain).
- Substitute APPNAME with a suitable short name for your Rails application, like typo for Typo. This must match whatever you set as the
Action namewhen setting up the Rails FCGI below. - Look for the line:
server.document-root = base + "/web/public/"You'll need to make sure this points to the right directory path. If you're Rails application is running under a secondary domain for your account, then the line should look something like this:
server.document-root = base + "/domains/secondarydomain.tld/web/public/"If not, then it's fine and you won't have to change it.
- Save lighttpd.conf and upload it to your account in the directory
~/etc/(e.g.,~/etc/lighttpd.conf)
~/var directory created on your account, with log and run subdirectories. This is the case by default, unless you deleted them on your own.
OK, Lighttpd has been configured and you've uploaded your application, so now it's time to start up your Lighttpd.
Setting up a boot-up action for Lighttpd
To ensure that your Rails application (and your site) will work at all times, the Lighttpd process must keep running constantly. It also needs to launch automatically when a server boots, so that you do not have to watch for our maintenances and emergencies and can assume that your site will work right away. The Virtualmin boot-up actions feature will take care of Lighttpd and make sure it starts and keeps running:
- Sign in to Virtualmin (see Account logins and important URLs).
- Select a domain from the drop-down in the left-hand navigation (your main domain should be already selected when you first login to Virtualmin). The domain you select here will be the one that you'll be adding your application to.
- Click Services and then Bootup Actions in the left-hand navigation. You should now see a the Virtualmin Bootup Actions page.
- Click Add Lighttpd. You should now see the Create Bootup Action page.
- For Action name, enter a suitable short name for your application, e.g. 'blog' (letters, digits, ‘-’ or ‘_’ are allowed, but not spaces).
- For Description, enter a suitable description.
- For Started?, leave the default value as Yes, so that the process is started right away and gets started each time the server boots.
- For Config file, enter the full path to your lighttpd.conf file (e.g., /users/home/yourusername/etc/lighttpd.conf). You can also browse for and select the lighttpd.conf file by clicking ….
- Finally, click Create.
Your Lighttpd process should now be available at your domain under the assigned port (e.g., http://yourdomain.com:XXXX/ where XXX is your port number), but you'll not yet be able to see your Rails application. Let's move on to the next step.
Setting up a boot-up action for Rails
To ensure that your Rails application (and your site) will work at all times, the Lighttpd process must keep running constantly. It also needs to launch automatically when a server boots, so that you do not have to watch for our maintenances and emergencies and can assume that your site will work right away. The Virtualmin boot-up actions feature will take care of Lighttpd and make sure it starts and keeps running:
- Sign in to Virtualmin (see Account logins and important URLs).
- Select a domain from the drop-down in the left-hand navigation (your main domain should be already selected when you first login to Virtualmin). The domain you select here will be the one that you'll be adding your application to.
- Click Services and then Bootup Actions in the left-hand navigation. You should now see a the Virtualmin Bootup Actions page.
- Click Add FCGI.. You should now see the Create Bootup Action page.
- For Action name, enter a suitable short name for your application, e.g. 'blog' (letters, digits, ‘-’ or ‘_’ are allowed, but not spaces). This name will be used to construct the socket file for Lighttpd to talk to, so make sure it matches - see above on editing lighttpd.conf.
- For Description, enter a suitable description.
- For Started?, leave the default value as Yes, so that the process is started right away and gets started each time the server boots.
- For Path to FCGI dispatcher, enter the full path to your FCGI dispatcher, typically dispatch.fcgi for Rails (e.g., /users/home/yourusername/web/public/dispatch.fcgi). You can also browse for and select the dispatch.fcgi file by clicking ….
- For Environment, select the Rails environment that you'd like your dispatcher to start under. 'Production' is recommended of course, since the Joyent shared servers are a production quality platform, not testing beds. Note that this can be overriden in your Rails app configuration, too.
- Finally, click Create. Your rails application should now be available at your domain under the assigned port (e.g., http://yourdomain.com:XXXX/ where XXX is your port number)
And that's it, your Rails application has now been deployed!
Proxying your port
To proxy the port number so that your application is accessible from your domain (i.e., accessable from http://yourdomain.com/ instead of http://yourdomain.com:XXXX/) see the following article:
Setting up multiple applications using Lighttpd
It's possible to run multiple applications on a single Lighttpd instance. To configure an additional application, simply add another 'Rails Application Configuration' section to your ~/etc/lighttpd.conf file. Once the addition has been made and the additional application has been configured, you can restart your boot-up action in Virtualmin for the changes to take effect.