Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save halilim/9950381 to your computer and use it in GitHub Desktop.
Save halilim/9950381 to your computer and use it in GitHub Desktop.
Install Nginx and Phusion Passenger on Ubuntu 12.04

Nginx

sudo add-apt-repository ppa:nginx/stable
sudo apt-get update
sudo apt-get install nginx

Passenger

Guide: http://www.modrails.com/documentation/Users%20guide%20Nginx.html

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7
sudo apt-get install apt-transport-https ca-certificates
sudo nano  /etc/apt/sources.list.d/passenger.list
# - Add
# deb https://oss-binaries.phusionpassenger.com/apt/passenger precise main
sudo chown root: /etc/apt/sources.list.d/passenger.list
sudo chmod 600 /etc/apt/sources.list.d/passenger.list
sudo apt-get update
sudo apt-get install nginx-extras passenger
sudo nano /etc/nginx/nginx.conf
# - Add/Uncomment passenger lines to:
# - passenger_root: run `passenger-config about root` and read the output
# - passenger_ruby: result of `passenger-config about ruby-command`
# - Add
# passenger_app_env production;
sudo service nginx restart

Vhost template

E.g. /etc/nginx/sites-available/example.conf

server {
  listen 80;
  server_name example.com;
  charset utf-8;
  root /home/app/apps/example/current/public;

  try_files $uri /system/maintenance.html @passenger;

  location @passenger {
    passenger_enabled on;
    passenger_friendly_error_pages off;
  }

  location ^~ /assets/ {
    # Only use gzip_static if you have .gz compressed assets *precompiled*
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  client_max_body_size 10M;
  keepalive_timeout 10;
}

Enable:

ln -s /etc/nginx/sites-available/example.conf /etc/nginx/sites-enabled/
nginx -t # Test the config
nginx -s reload # Reload config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment