Skip to content

Instantly share code, notes, and snippets.

@wsaribeiro
Created March 11, 2016 17:08
Show Gist options
  • Save wsaribeiro/891712ed6d20ad2beeed to your computer and use it in GitHub Desktop.
Save wsaribeiro/891712ed6d20ad2beeed to your computer and use it in GitHub Desktop.
Nginx Caching
##########
# GZIP
##########
gzip on;
gzip_types text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
##########
# CACHE
##########
location ~ \.(css|htc|less|js|js2|js3|js4)$ {
add_header Pragma "public";
add_header Cache-Control "max-age=31536000, public";
}
location ~ \.(html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml)$ {
add_header Pragma "public";
add_header Cache-Control "max-age=3600, public";
}
location ~ \.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|wav|wma|wri|woff|xla|xls|xlsx|xlt|xlw|zip)$ {
add_header Pragma "public";
add_header Cache-Control "max-age=31536000, public";
add_header Link "<$scheme://$host$uri>; rel=\"canonical\"";
}
##########
# CORS
##########
location ~ \.(ttf|ttc|otf|eot|woff|font.css)$ {
add_header Access-Control-Allow-Origin "*";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment