Skip to content

Instantly share code, notes, and snippets.

@dayvough
Last active September 26, 2016 10:58
Show Gist options
  • Save dayvough/b6e75be8603f71a7cfe54453be71b202 to your computer and use it in GitHub Desktop.
Save dayvough/b6e75be8603f71a7cfe54453be71b202 to your computer and use it in GitHub Desktop.
Unicorn + Rails + Nginx
upstream app_name {
server unix:///home/deploy/app_name/shared/pids/unicorn.sock;
}
server {
listen 80;
server_name example.com;
root /home/deploy/app_name/current/public;
access_log /var/log/nginx/nginx.access.log;
error_log /var/log/nginx/nginx.error.log info;
location ~ ^/(assets)/ {
root /home/deploy/app_name/current/public;
expires max;
add_header Cache-Control public;
if ($request_filename ~* ^.*?\.(eot)|(ttf)|(woff)|(svg)|(otf)$){
add_header Access-Control-Allow-Origin *;
}
}
location ~ ^/(fonts)/ {
root /home/deploy/app_name/current/public;
expires max;
add_header Cache-Control public;
if ($request_filename ~* ^.*?\.(eot)|(ttf)|(woff)|(svg)|(otf)$){
add_header Access-Control-Allow-Origin *;
}
}
location / {
proxy_pass http://app_name;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
if (-f $request_filename) { break; }
if (-f $request_filename/index.html) { rewrite (.*) $1/index.html break; }
if (-f $request_filename.html) { rewrite (.*) $1.html break; }
}
# Now this supposedly should work as it gets the filenames
# with querystrings that Rails provides.
# BUT there's a chance it could break the ajax calls.
location ~* \.(ico|css|gif|jpe?g|png)(\?[0-9]+)?$ { expires max; break; }
location ~ ^/javascripts/.*\.js(\?[0-9]+)?$ { expires max; break; }
# Error pages
error_page 500 502 503 504 /500.html;
location = /500.html {
root /home/deploy/app_name/current/public;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment