Created
August 11, 2017 10:56
-
-
Save timotheos/57a15cb4c6e915ad15cd8e3180100175 to your computer and use it in GitHub Desktop.
Unicorn + Rails + Nginx (credits to dayvough)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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