Skip to content

Instantly share code, notes, and snippets.

@chrisedington
Created October 27, 2016 09:04
Show Gist options
  • Save chrisedington/d8a3ef9840f44192fc502057666acbab to your computer and use it in GitHub Desktop.
Save chrisedington/d8a3ef9840f44192fc502057666acbab to your computer and use it in GitHub Desktop.
# This is a template. Referenced variables (e.g. $RAILS_ROOT) need
# to be rewritten with real values in order for this file to work.
# To learn about all the directives used here, and more, see
# http://nginx.org/en/docs/dirindex.html
# define our application server
upstream unicorn {
server app:3000;
}
server {
listen 80;
# define our domain; CHANGE ME
server_name example.myapp.com;
# define the public application root
root $RAILS_ROOT/public;
index index.html;
# define where Nginx should write its logs
access_log $RAILS_ROOT/log/nginx.access.log;
error_log $RAILS_ROOT/log/nginx.error.log;
# deny requests for files that should never be accessed
location ~ /\. {
deny all;
}
location ~* ^.+\.(rb|log)$ {
deny all;
}
# serve static (compiled) assets directly if they exist (for rails production)
location ~ ^/(assets|images|javascripts|stylesheets|swfs|system)/ {
try_files $uri @rails;
access_log off;
gzip_static on; # to serve pre-gzipped version
expires max;
add_header Cache-Control public;
# Some browsers still send conditional-GET requests if there's a
# Last-Modified header or an ETag header even if they haven't
# reached the expiry date sent in the Expires header.
add_header Last-Modified "";
add_header ETag "";
break;
}
# send non-static file requests to the app server
location / {
try_files $uri @rails;
}
location @rails {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment