Skip to content

Instantly share code, notes, and snippets.

@richardsweeney
Last active February 2, 2016 08:30
Show Gist options
  • Save richardsweeney/55c058d1f550b61494e7 to your computer and use it in GitHub Desktop.
Save richardsweeney/55c058d1f550b61494e7 to your computer and use it in GitHub Desktop.
NGINX site example conf
server {
listen 80;
server_name www.site.com;
return 301 $scheme://site.com$request_uri;
}
server {
listen 80;
root /usr/share/nginx/site/current;
index index.php index.html index.htm;
server_name site.com;
access_log /var/log/nginx/site.access.log;
#Fast CGI cache config
set $skip_cache 0;
# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
set $skip_cache 1;
}
if ($query_string != "") {
set $skip_cache 1;
}
# Don't cache uris containing the following segments
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
set $skip_cache 1;
}
# Don't use the cache for logged in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
set $skip_cache 1;
}
# Specify a charset
charset utf-8;
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;
location ~ \.(woff|css|htc|less|js|js2|js3|js4|svg|png|gif|jpeg|jpg)$ {
expires 31536000s;
add_header Pragma "public";
add_header Cache-Control "max-age=31536000, public";
}
rewrite ^/sitemap_index\.xml$ /index.php?sitemap=1 last;
rewrite ^/([^/]+?)-sitemap([0-9]+)?\.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
location / {
try_files $uri $uri/ /index.php?$args;
proxy_read_timeout 150;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache wordpress;
fastcgi_cache_valid 10m;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment