/ guide

Setting Up Passenger and Nginx

I'd like a clear step-by-step reference on how to set up a Nginx server on Ubuntu that uses Passenger to run web apps, so I'm posting it here for reference. Hopefully others will find this useful too! These steps are specifically to run a rails app running on Ubuntu 14.04, but it shouldn't be too hard to figure out how to make it work for another language/framework.

Install Passenger + Nginx via Phusion's APT repository

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7

sudo apt-get install -y apt-transport-https ca-certificates

sudo sh -c 'echo deb <https://oss-binaries.phusionpassenger.com/apt/passenger> trusty main > /etc/apt/sources.list.d/passenger.list'

sudo apt-get install -y nginx-extras passenger

Enable Passenger

  • Edit /etc/nginx/nginx.conf and uncomment include /etc/nginx/passenger.conf;

Create Nginx service

  • Remove /etc/init.d/nginx if it exists

Create an upstart script located at "/etc/init/nginx.conf" that contains the following:

# nginx

description "nginx http daemon"
author "George Shammas <georgyo@gmail.com>"

start on (filesystem and net-device-up IFACE!=lo)
stop on runlevel [!2345]

env DAEMON=/usr/sbin/nginx
env PID=/var/run/nginx.pid

expect fork
respawn limit 10 5
#oom never

pre-start script
if [ $? -ne 0 ]
then exit $?
end script

exec $DAEMON

Configure Nginx

  • In /etc/nginx/nginx.conf add rails_env <RAILS_ENV_YOU_WANT_APP_TO_RUN_UNDER>; at the end of the http block

  • In /etc/nginx/sites-enabled/default put the following in the server block

listen 80;

server_name localhost;

root /home/ubuntu/sales-tool/current/public;

passenger_enabled on;

Make sure this is the only code in this block (comment everything else out)

Run server and pray

sudo service nginx restart