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.
this configuration need nginx caching enable?
I get a 403 forbidden from nginx after adding thos parameters in Plesk
No this is Disk Caching mode and not needed nginx caching.
I tried this method but plesk nginx cache much better then this.
I don’t know how :/
I disable nginx cache and tried this.
With nginx cache firts byte 0.372s Firts BYTE GRADE A
With out nginx cache + wp super cache 0.45 and more Firts BYTE GRADE C
What do you think about this?
I think that you must to see your PHP Version, and also your OPCache setting. In many case the nginx caching is more fast than wp super cache, because wp super cache not use gzipped file correctly like wp rocket, and also nginx cache working on memory and not disk.
But pay attention, if you have mobile version and desktop version sometimes not working well nginx cache.
For me best perfomance is this: https://francescopantisano.it/configure-plesk-nginx-nginx-cache-with-wp-rocket/
My php version https://188.34.206.115/smb/web/php-info/id/2 i use plesk panel.
I have Astra theme it is responsible.
Thanks for your reply. I have a few questions. If you answer them i will be happy
1) How can you compile above codes? Without them plugins don’t work? (Wp rocket, WP Super Cache Plugin or etc)
https://docs.wp-rocket.me/article/37-nginx-configuration-for-wp-rocket i read this abd this https://github.com/SatelliteWP/rocket-nginx there are not any code for plesk with above? How can you create that above codes for plugins?
2) https://www.gulshankumar.net/install-wordpress-with-lemp-on-ubuntu-18-04/ i read this an liked it
How can i use that (FastCGI If you want to use FastCGI Cache then implement below Server Block instead) code for plesk?
Because in plesk ssl urls and cache pats are different! Is it necessary that editing conf files at server? or we can do this Additional nginx directives? What do you think this code is good?
3) Nginx default cache has a timeout 5 second what is it? I use cloudflare and it has cache system we can cache static pages for 1 years for example!
In gulshankumar site above there is a code:
# NGINX Cache path
fastcgi_cache_path /var/www/cache levels=1:2 keys_zone=WORDPRESS:100m inactive=6h;
fastcgi_cache_key “$scheme$request_method$host$request_uri”;
fastcgi_cache_use_stale error timeout invalid_header http_500;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
there is a inactive hour and etc and also
fastcgi_cache_valid 200 301 24h;
I dont know what are they but in plesk nginx cache there are only a yimeout 5 second :S
Is this codes good or nginx cache is enough for all?
4) I use Autoptimizer and i thnik is is not good for my astra web site.
lazy load option not working. I onlu installed and activated it an i use it.
Is there special anythink for plesk nginx?
5) I tried gzip bor nginx but there are no ipmprvement.
https://developers.google.com/speed/pagespeed/insights/?hl=tr&url=https%3A%2F%2Fwifisifrekirici.com%2F
I have 3 lcp and i down know how to lower this
Thanks for your help. You are the best.