WordPress custom Nginx Rules

Plesk + Cpanel nginx directives for wordpress, this is the fastest formula we came up with.

if (!-e $request_filename) { rewrite ^(.*)$ /index.php break; }
rewrite /wp-config.php /forbidden last;
rewrite /install.php /forbidden last;
rewrite ^(.*)/uploads/(.*).php(.?) /forbidden last;
rewrite /xmlrpc.php /forbidden last;
location = /forbidden { deny all; }

location = /nginx.conf { deny all; }

location ~* \.(txt)$ { charset utf-8; }

location ~* \.(png|jpg|jpeg|gif|ico|bmp|img|ttf|otf|eot|svg|woff)$ {
expires 90d;
add_header Pragma public;
add_header Cache-Control public;
try_files $uri @fallback;
}

location ~* \.(bz2|exe|gz|pdf|rar||tgz|zip)$ {
expires 2w;
add_header Pragma public;
add_header Cache-Control public;
try_files $uri @fallback;
}

location ~* \.(ac3|avi|flv|iso|mp3|mp4|mpeg|mpg|ogg|qt|rm|swf|wav)$ {
expires 1w;
add_header Pragma public;
add_header Cache-Control public;
try_files $uri @fallback;
}

location ~* \.(js|css|htm|html|xhtml|xml|dat|doc|docx|dts|ppt|pptx|tar|txt|xls|xlsx)$ {
expires 1w;
add_header Pragma public;
add_header Cache-Control public;
try_files $uri @fallback;
}

gzip on;
gzip_proxied any;
gzip_min_length 100;
gzip_buffers 8 16k; # number size, default 32 4k|16 8k
gzip_types text/css text/plain text/javascript application/javascript application/json application/x-javascript application/xml application/xml+rss application/xhtml+xml application/x-font-ttf application/x-font-opentype application/vnd.ms-fontobject image/svg+xml image/x-icon application/rss+xml application/atom_xml;
gzip_vary on;
gzip_comp_level 9;
gzip_http_version 1.0;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";

if (!-e $request_filename) {
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
rewrite ^(/[^/]+)?(/wp-.*) $2 last;
rewrite ^(/[^/]+)?(/.*\.php) $2 last;
}

set $no_cache 0;

if ( $http_cookie ~* "comment_author_|wordpress_(?!test_cookie)|wp-postpass_" ) {
set $no_cache 1;
}

if ($request_uri ~* "/(wp-admin/|wp-login.php)"){
set $no_cache 1;
}

Hit the Talk with us Now button to see what we can do for you. No sales pressure, no queue time, just a real conversation with our team.