Skip to content

Instantly share code, notes, and snippets.

@CodyStringham
Last active February 6, 2016 08:04
Show Gist options
  • Select an option

  • Save CodyStringham/833f0f97e2ca2e18b52b to your computer and use it in GitHub Desktop.

Select an option

Save CodyStringham/833f0f97e2ca2e18b52b to your computer and use it in GitHub Desktop.
Reverse proxy all day

Setting up NGINX and PUMA

This is a working document for me, hopefully I will eventually figure out how to run multiple puma apps on the same server. First of all, lets start fresh here.

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ABF5BD827BD9BF62

Now add this to the bottom of /etc/apt/sources.list:

deb http://nginx.org/packages/ubuntu/ precise nginx

And install:

sudo apt-get purge nginx*
sudo apt-get update
sudo apt-get install nginx
nginx -v
sudo service nginx start

Getting Started (Ubuntu)

Start by removing the default settings

sudo rm /etc/nginx/conf.d/sites-enabled/default

You may need to add this to your /etc/nginx/nginx.conf file:

include /etc/nginx/sites-enabled/*;

This will include the default ubuntu structure, otherwise nginx will just look inside /etc/nginx/conf.d/*.

add a my_app.conf

in /etc/nginx/sites-available/my_app.conf:

upstream my_app {
  server unix:/home/deploy/my_app/shared/tmp/sockets/puma.sock;
}

server {
  listen 80;
  server_name my_app.com www.my_app.com; # what to listen for
  root /home/deploy/my_app/public;

  location / {
    proxy_pass http://my_app; # links upstream
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }

  location ~ ^/(assets|fonts|system)/|favicon.ico|robots.txt {
    root /home/deploy/stringy/current/public;
    gzip_static on;
    expires max;
    add_header Cache-Control public;
    add_header Last-Modified "";
    add_header ETag "";
  }

}

Then symlink and restart:

sudo ln -sf /etc/nginx/sites-available/my_app.conf /etc/nginx/sites-enabled/my_app.conf
sudo service nginx restart

Puma

This part gets really easy, simply navigate to the app and start up puma (start fresh):

ps ax | grep puma
pkill -f puma
bundle exec puma -e production -b unix:///var/run/my_app.sock

If everything boots up without errors, deamonize the process with -d.

Whammo! You're totally doing it bruh!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment