Skip to content

Instantly share code, notes, and snippets.

@zanematthew
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zanematthew/adfb6ae19a0765a8bb8e to your computer and use it in GitHub Desktop.
Save zanematthew/adfb6ae19a0765a8bb8e to your computer and use it in GitHub Desktop.
fastcgi_cache_path /home/foo/site.com/cache levels=1:2 keys_zone=WORDPRESS:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
server {
# also use www here
server_name site.com;
access_log /home/foo/site.com/logs/access.log;
error_log /home/foo/site.com/logs/error.log;
root /home/foo/site.com/public/;
index index.php;
# Cache
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;
}
## End Cache
# Rewrite multisite '.../wp-.*' and '.../*.php'.
if (!-e $request_filename) {
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
rewrite ^(/[^/]+)?(/wp-.*) $2 last;
rewrite ^(/[^/]+)?(/.*\.php) $2 last;
}
location / {
try_files $uri wp$uri/ /wp/index.php?$args;
index index.php;
}
rewrite ^/(wp-.*.php)$ /wp/$1 last;
rewrite ^/(wp-(content|admin|includes).*) /wp/$1 last;
location ~* ^.+\.(jpe?g|gif|js|css|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mp3)$ {
expires 30d;
rewrite ^/(wp-(content|admin|includes).*) /wp/$1 break;
}
location ~ \.php$ {
try_files $uri =404;
#try_files $uri wp$uri/ /wp/index.php?$args;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
# Caching (FastCGI) configuration
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache WORDPRESS;
fastcgi_cache_valid 60m;
}
# Caching (FastCGI) configuration
location ~ /purge(/.*) {
fastcgi_cache_purge WORDPRESS "$scheme$request_method$host$1";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment