Skip to content

Instantly share code, notes, and snippets.

@0xMatt
Created June 28, 2015 22:59
Show Gist options
  • Save 0xMatt/dfb925f140e3c8535a91 to your computer and use it in GitHub Desktop.
Save 0xMatt/dfb925f140e3c8535a91 to your computer and use it in GitHub Desktop.
nginx setup
# Expire rules for static content
# No default expire rule. This config mirrors that of apache as outlined in the
# html5-boilerplate .htaccess file. However, nginx applies rules by location,
# the apache rules are defined by type. A consequence of this difference is that
# if you use no file extension in the url and serve html, with apache you get an
# expire time of 0s, with nginx you'd get an expire header of one month in the
# future (if the default expire rule is 1 month). Therefore, do not use a
# default expire rule with nginx unless your site is completely static
# cache.appcache, your document html and data
location ~* \.(?:manifest|appcache|html?|xml|json)$ {
expires -1;
# access_log logs/static.log;
}
# Feed
location ~* \.(?:rss|atom)$ {
expires 1h;
add_header Cache-Control "public";
}
# Media: images, icons, video, audio, HTC
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
expires 1M;
access_log off;
add_header Cache-Control "public";
}
# CSS and Javascript
location ~* \.(?:css|js)$ {
expires 1y;
access_log off;
add_header Cache-Control "public";
}
# WebFonts
# If you are NOT using cross-domain-fonts.conf, uncomment the following directive location ~* \.(?:ttf|ttc|otf|eot|woff|woff2)$ {
expires 1M;
access_log off;
add_header Cache-Control "public";
add_header Access-Control-Allow-Origin "*";
}
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript texx
t/xml application/xml application/javascript application/rss+xml text/javascriptt
image/svg+xml application/vnd.ms-fontobject application/x-font-ttf font/opentypp
e;
# PHP-FPM FastCGI server
# network or unix domain socket configuration
upstream php-fpm {
server unix:/var/run/php5-fpm.sock;
}
# pass the PHP scripts to FastCGI server
#
# See conf.d/php-fpm.conf for socket configuration
#
index index.php index.html index.htm;
location ~ \.php$ {
try_files $uri =404;
fastcgi_intercept_errors on;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass php-fpm;
}
server {
listen 80;
server_name www.lithecms.com lithecms.com;
root /home/matthew/www/lithecms.com/public;
index index.php;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
include /etc/nginx/default.d/*.conf;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment