• Our team is looking to connect with folks who use email services provided by Plesk, or a premium service. If you'd like to be part of the discovery process and share your experiences, we invite you to complete this short screening survey. If your responses match the persona we are looking for, you'll receive a link to schedule a call at your convenience. We look forward to hearing from you!
  • We are looking for U.S.-based freelancer or agency working with SEO or WordPress for a quick 30-min interviews to gather feedback on XOVI, a successful German SEO tool we’re looking to launch in the U.S.
    If you qualify and participate, you’ll receive a $30 Amazon gift card as a thank-you. Please apply here. Thanks for helping shape a better SEO product for agencies!
  • The BIND DNS server has already been deprecated and removed from Plesk for Windows.
    If a Plesk for Windows server is still using BIND, the upgrade to Plesk Obsidian 18.0.70 will be unavailable until the administrator switches the DNS server to Microsoft DNS. We strongly recommend transitioning to Microsoft DNS within the next 6 weeks, before the Plesk 18.0.70 release.
  • The Horde component is removed from Plesk Installer. We recommend switching to another webmail software supported in Plesk.

Nginx directives for WP super cache on Plesk

blueberry

Basic Pleskian
I have tried to add the following nginx directives to

Additional nginx directives​

I only use nginx and I want to use WP super cache in expert mode with Nginx. The following code create the $cache_uri variable, then it checks some exception. Then at the end, it checks if there is an existing cached page in a folder, if yes it returns this page.


Code:
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';
}

# 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 ~ / {
    index index.php;
    try_files /wp-content/cache/supercache/$http_host/$cache_uri/index.html $uri $uri/ /index.php ;
}

However, i think it does not work because it takes 300ms for my server to answer a request when the the file is cached. Usually, static files are delivered in 30ms.
I checked my variables they look ok but I guess the problem could come from the folder path. I don't know in which context I am. is /wp-content the root in this case? Maybe the absolute path should be added?

What do you think?
 
I looked into the cache folder of wp super cache and found that the file was not index.html.
There are two files. Wp super cache chooses the file depending on whether you ticked Compress pages so they’re served more quickly to visitors. (Recommended) or not
1602142189443.png
So since i ticked compress pages,

Code:
location ~ / {
    index index.php;
    try_files /wp-content/cache/supercache/$http_host/$cache_uri/index-https.html.gz $uri $uri/ /index.php ;
}

It still does not work but it is a good start.
 
The thing is basically "the problem" I will describe to you...
The rules you are using are the correct ones... ( I have used Super cache over the years ) but Plesk creates the nginx rules every time you modify parameters of that part on the panel.

This part does not work on Plesk as it should be
location ~ / { index index.php; try_files /wp-content/cache/supercache/$http_host/$cache_uri/index-https.html.gz $uri $uri/ /index.php ; }

Because Plesk inserts a similar rule by code...

You need to modify the Nginx Templates as this documentation shows...

You have to copy
/usr/local/psa/admin/conf/templates/default/domain/nginxDomainVirtualHost.php
to
/usr/local/psa/admin/conf/templates/custom/domain/nginxDomainVirtualHost.php

and then modify it in order to include this location ~ / rule as you need it ( it´s already there but is different.. )
Because every time you make a change on the panel you will get this: ( this is an Example of a nginx domain configuration generated file found in /var/www/vhosts/system/domain.zzz/conf/nginx.conf )

1604896871861.png

And you need it like this:

1604897154780.png

The modification you need to do is only add one line...

Change from this lines on /usr/local/psa/admin/conf/templates/default/domain/nginxDomainVirtualHost.php ( do not touch that file )
1604897448628.png

To this modified file /usr/local/psa/admin/conf/templates/custom/domain/nginxDomainVirtualHost.php ( having this line added )
1604897532988.png



I also create a set of rules in one file regarding all the super cache setup and include it in every domain that i need it
1604897635278.png
my /etc/nginx/include/wordpress has this

Code:
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';
}
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';
}

# Set the cache file
set $cachefile "/wp-content/cache/supercache/$http_host/$cache_uri/index.html";
if ($https ~* "on") {
        set $cachefile "/wp-content/cache/supercache/$http_host/$cache_uri/index-https.html";
}


#location ~* /wp-includes/.*.php$ {
#    deny all;
#    access_log off;
#    log_not_found off;
#}

#location ~* /wp-content/.*.php$ {
#    deny all;
#    access_log off;
#    log_not_found off;
#}

location ~* /(?:uploads|files)/.*.php$ {
    deny all;
    access_log off;
    log_not_found off;
}



And there it is... super cache working at nginx level ( awesomely fast ) and not even using cpu resources for PHP ( some extra configuration needed on the plugin )
 
Last edited:
@Cike76 You did an impressive job. Can you tell me what is your time to first byte when a page is cached? (Inspect > Network > reload page). It would be kind to mention how far you are located from your server. (in miles or kilometers) so that i can compare to my situation.
 
Hi,

great topic.

Did you compare this solution with the default Plesk Nginx FastCGI cache?
 
Last edited:
@blueberry , @Cike76

Indeed... you 2 are GOOD!!!! I know all the concepts (why/how) this thread is talking about, but executing/implementing... uhm, servers/networking/nginx is not the top of my skills list.

is it possible to give the summary/settings on the best (ie. fastest performance) you are using?

thanks!!!
Happy New Years

FYI. Plesk Admins, etc ... note: this type of thread SHOULD be important for anyone using Plesk to host their websites.
 
Indeed... you 2 are GOOD!!!! I know all the concepts (why/how) this thread is talking about, but executing/implementing... uhm, servers/networking/nginx is not the top of my skills list.

is it possible to give the summary/settings on the best (ie. fastest performance) you are using?
 
@Cike76
In my installation I couldn't find the location in this file. I guess the directives changed and this lines needs to be added elsewhere?
/usr/local/psa/admin/conf/templates/default/domain/nginxDomainVirtualHost.php
 
Back
Top