I’ve got a 512MB Slicehost instance that I needed to launch a new Rails app (details coming soon). Since 512MB isn’t a whole lot of memory anymore, I wanted to optimize the services on this machine as much as possible. The most efficient setup appeared to be running nginx, Passenger-Nginx, and Ruby Enterprise Edition. It was actually pretty easy to get all this running and would have been even easier had I followed the correct order of operations. Nginx doesn’t support dynamically compiled runtime modules. Everything has to be built-in at compile time. Because of this, running:
$ sudo aptitude install nginxwill get you nothing useable besides the init script. Instead, the best approach is:
- Install Ruby Enterprise Edition
- Install nginx-passenger
- Adjust paths
- Modify the
- Reinstall all gems for REE
- Tweak the nginx config
nginxdissitescripts to make it more ubuntu-y
$ /opt/ruby-enterprise/bin/passenger-install-nginx-moduleNext you want to tweak the ubuntu
/etc/init.d/nginxscript to reflect the new paths. You need to change the two lines that read:
PATH=/opt/nginx/sbin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/opt/nginx/sbin/nginxNext, you need to add the Ruby Enterprise Edition interpreter to your path. Open
/etc/login.defsand update the paths settings with the location of Ruby Enterprise. Installing gems is pretty straight forward. There are a few small tweaks to make to the nginx config file so that it works more like the ubuntu package. At the top of
nginx.confadd/change these settings:
user www-data; worker_processes 4; error_log /var/log/nginx/error.log; pid /var/run/nginx.pid;In the
include /etc/nginx/sites-enabled/*;Finally, it’s time to create the
#!/bin/bash # nginxensite if [ -z $1 ]; then echo echo "You must specify a site name" exit 0 fi NGINX_CONF=/etc/nginx CONF_FILE="$1" AVAILABLE_PATH="$NGINX_CONF/sites-available/$CONF_FILE" ENABLED_PATH="$NGINX_CONF/sites-enabled/$CONF_FILE" echo if [ -e $AVAILABLE_PATH ]; then ln -s $AVAILABLE_PATH $ENABLED_PATH echo "$1 has been enabled" echo "run /etc/init.d/nginx reload to apply the changes" else echo "$AVAILABLE_PATH does not exist" exit 1 fiand
#!/bin/bash # nginxdissite if [ -z $1 ]; then echo echo "You must specify a site name" exit 0 fi NGINX_CONF=/etc/nginx CONF_FILE="$1" AVAILABLE_PATH="$NGINX_CONF/sites-available/$CONF_FILE" ENABLED_PATH="$NGINX_CONF/sites-enabled/$CONF_FILE" echo if [ -e $ENABLED_PATH ]; then rm $ENABLED_PATH echo "$1 has been disabled" echo "run /etc/init.d/nginx reload to apply the changes" else echo "$ENABLED_PATH does not exist, ignoring" fiThere you go, a working nginx install for your rails apps in less than an hour.
Did you like this? Please share:
On it becoming Day 2 and Leaving Amazon
Making the jump during a pandemic was daunting but there is just something about startups.
The Lost Year: A Failed Experiment to Switch Away From Mac
Fed up with the Apple Keyboard, I bought a ThinkPad, installed Linux, and promptly decided that I hated computers.