Plesk Nginx WP Super Cache Expert Mode Settings

Have you got a wordpress site and you want to optimize it?
The simple way to take fast your website is:

  • Install WPSuper Cache Plugin
  • Setting Server side Nginx

Install WP Super Cache Plugin

The installation of WPSuper Cache is easy, just download the plugin and then upload it on our wordpress website.

Setting WP Super Cache

Now i show to you how to set wp super cache in “Expert mode”, remember that this mode require the change on the server for nginx configuration.

Enable Caching ON

Then we must to set the Expert Mode, and then suggest some setting:

Settings Server side Nginx

Now we need to set the configuration of nginx on our server, in this case i configure a Plesk Server.
We must go in the Domain Setting -> Apache & nginx Settings
In the bottom we find “Additional nginx directives

We must to enable:

  • GZIP compression for the page that we serve on the client
  • Header Cache Control to declase a cache browser for the js, css, image etc..
  • Location to find wpsupercache generated file
  • Security setting 
### WP Super Cache Below ###
set $cache_uri $request_uri;

# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
	set $cache_uri 'null cache';
}

# GZIP Compression
gzip on;
gzip_disable "MSIE [1-6]\\.(?!.*SV1)";
gzip_min_length 1100;
gzip_buffers 4 32k;
gzip_proxied any;
gzip_comp_level 9;
gzip_types text/plain text/css application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript image/x-icon image/bmp image/svg+xml;
gzip_vary on;

# NGINX Caching
location ~* \.(?:ico|css|js|gif|jpe?g|png|svg|woff)$ {
	expires 14d;
	add_header Cache-Control "public, no-transform";
	log_not_found off;
}

location ~* \.(jpg|jpeg|gif|png)$ {
	expires 14d;
	add_header Cache-Control "public, no-transform";
	log_not_found off;
}

location ~* \.(pdf|css|html|js|swf)$ {
	expires 14d;
	add_header Cache-Control "public, no-transform";
	log_not_found off;
}

location ~ \.css {
	add_header  Content-Type    text/css;
}
location ~ \.js {
	add_header  Content-Type    application/x-javascript;
}

if ($query_string != "") {
	set $cache_uri 'null cache';
}

# Don't cache uris containing the following segments
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 $cache_uri 'null cache';
}

# Don't use the cache for logged in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") {
	set $cache_uri 'null cache';
}

# Use cached or actual file if they exists, otherwise pass request to WordPress
location ~ / {
	try_files /wp-content/cache/supercache/$http_host/$cache_uri/index.html $uri $uri/ /index.php ;
}

# WORDPRESS PERMALINKS
if (!-e $request_filename) {
	rewrite ^(.+)$ /index.php?q=$1 last;
}

# SECURITY
location ~* wp-config.php { deny all; }
location ~* "^/wp-content/(?!plugins/).*\.php" { deny all; }

Now you can test your site on pagespeed and see the difference!
If you want much performance you can use Autoptimize WordPress plugin to minify js, css and html.