Last active
December 12, 2017 09:01
-
-
Save seb/6506622 to your computer and use it in GitHub Desktop.
Nginx + Puma + Rails + Cache Configuration File Replace example.com.
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 example.com { | |
server unix:///var/www/example.com/shared/sockets/puma.sock fail_timeout=0; | |
} | |
server { | |
listen 80; | |
server_name *.example.com; | |
return 301 http://example.com$request_uri; | |
} | |
server { | |
listen 80; | |
server_name example.com; | |
root /var/www/example.com/current/public; | |
access_log /var/log/nginx/example.com_access.log timed_combined; | |
error_log /var/log/nginx/example.com_error.log; | |
rewrite_log off; | |
location / { | |
try_files /cache/$uri /cache/$uri.html $uri $uri/index.html $uri.html @rails; | |
gzip_static on; | |
expires max; | |
add_header Cache-Control public; | |
} | |
# Serving assets pipeline with a long expires date | |
location ~ ^/(images|system|assets)/ { | |
gzip_static on; | |
expires 1y; | |
add_header Cache-control public; | |
add_header ETag ""; | |
break; | |
} | |
location ~ /(500.html|404.html|422.html|maintenance.html|favicon.ico|robots.txt|(.*).pdf) { | |
root /var/www/example.com/current/public; | |
} | |
location @rails { | |
proxy_pass http://example.com; | |
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_next_upstream error timeout invalid_header http_502; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment