Skip to content

Instantly share code, notes, and snippets.

@nghuuphuoc
Last active December 30, 2015 21:19
Show Gist options
  • Save nghuuphuoc/7886804 to your computer and use it in GitHub Desktop.
Save nghuuphuoc/7886804 to your computer and use it in GitHub Desktop.
Nginx config for Wordpress Super Cache plugin
server {
set $supercache_file '';
set $supercache_uri $request_uri;
if ($request_method = POST) {
set $supercache_uri '';
}
# Using pretty permalinks, so bypass the cache for any query string
if ($query_string) {
set $supercache_uri '';
}
if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
set $supercache_uri '';
}
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") {
set $supercache_uri '';
}
# if we haven't bypassed the cache, specify our supercache file
# REMEMBER to set the cache dir writable
if ($supercache_uri ~ ^(.+)$) {
set $supercache_file /wp-content/cache/supercache/$http_host/$1index.html;
}
# only rewrite to the supercache file if it actually exists
if (-f $document_root$supercache_file) {
rewrite ^(.*)$ $supercache_file break;
}
// ... Other Wordpress rewrite rules come here ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment