Last Updated: February 25, 2016
·
3.107K
· tmartin314

Symlink nginx config file for Rails and Capistrano

Add your nginx.conf file to /config dir. Here's an example file that uses puma server:

upstream puma {
  server unix:///var/www/appname/shared/tmp/sockets/appname-puma.sock;
}

server {
  listen 80 default_server deferred;
  # server_name example.com;

  root /var/www/appname/current/public;
  access_log /var/www/appname/current/log/nginx.access.log;
  error_log /var/www/appname/current/log/nginx.error.log info;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  try_files $uri/index.html $uri @puma;
  location @puma {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;

    proxy_pass http://puma;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 10M;
  keepalive_timeout 10;
}

Remove the default nginx file:

sudo rm /etc/nginx/sites-enabled/default

Link your file

sudo ln -nfs "/var/www/appname/current/config/nginx.conf" "/etc/nginx/sites-enabled/appname"