• Please be aware: Kaspersky Anti-Virus has been deprecated
    With the upgrade to Plesk Obsidian 18.0.64, "Kaspersky Anti-Virus for Servers" will be automatically removed from the servers it is installed on. We recommend that you migrate to Sophos Anti-Virus for Servers.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

Question How to activate nginx cache from plesk correctly

strelok

New Pleskian
Hello, I would like clarify that I don't speak good english, but I will try.

I have activated the Nginx cache from Plesk, and to know if it is working correctly I want it to return the "cache status". To achieve that I have added this line "add_header X-NG-Cache-Status $upstream_cache_status;" in "Additional nginx directives".

I have 2 problems:

1- The browser shows 2 more headers (and I have specified one). In the attached image you can see "x-cache-status" and the one that I added. If we remove the line that I mentioned earlier, both disappear. (Curious) Link: header cache nginx.png

2- This is the main problem. The state is never "HIT", the first time is "MISS" and then it is always "BYPASS". I tried to configure the BYPASS options, but it keeps coming out. Link: caché nginx opciones.png

Do I have to configure the cookies? I currently have that field empty.

What is the correct configuration for a wordpress? (I just think that adding / wp-admin / is enough)
 
Hello, I would like clarify that I don't speak good english, but I will try.

I have activated the Nginx cache from Plesk, and to know if it is working correctly I want it to return the "cache status". To achieve that I have added this line "add_header X-NG-Cache-Status $upstream_cache_status;" in "Additional nginx directives".

I have 2 problems:

1- The browser shows 2 more headers (and I have specified one). In the attached image you can see "x-cache-status" and the one that I added. If we remove the line that I mentioned earlier, both disappear. (Curious) Link: header cache nginx.png

2- This is the main problem. The state is never "HIT", the first time is "MISS" and then it is always "BYPASS". I tried to configure the BYPASS options, but it keeps coming out. Link: caché nginx opciones.png

Do I have to configure the cookies? I currently have that field empty.

What is the correct configuration for a wordpress? (I just think that adding / wp-admin / is enough)

Hello,

currently Plesk Nginx cache feature do not bypass cache on cookies, but do the opposite (you have to set each cookie you want to cache with Nginx).

About location to not cache for wordpress, here a list :

Code:
/wp-admin/
/wp-[a-zA-Z0-9-]+.php
/feed/
/index.php
/[a-z0-9_-]+-sitemap([0-9]+)?.xml
/sitemap(_index)?.xml
/wp-comments-popup.php
/wp-links-opml.php
/wp-locations.php
/wp-.*.php
/xmlrpc.php
/wp-app.php
/wp-login.php
/wp-register.php
/wp-mail.php
 
with respect to the list that you passed me. Adding the line: /wp-[a-zA-Z0-9-]+.php you do not think it includes all these lines?

/wp-comments-popup.php
/wp-links-opml.php
/wp-locations.php
/wp-.*.php
/xmlrpc.php
/wp-app.php
/wp-login.php
/wp-register.php
/wp-mail.php
/wp-admin/


Finally, with respect to cookies, I need more help. What cookies should I specify exactly?

Thank you very much,

Regards
 
@strelok

I will return to your questions later, but first I have to state that the recommended list should actually be

/wp-admin/
/xmlrpc.php
/wp-(app|cron|login|register|mail).php (or: 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


and, in the case that you use WooCommerce, the list should be extended with

/shop.*
/cart.*
/checkout.*
/my-account.*


and note that it cannot do harm to add WooCommerce related cache exclusions anyway.

Also note that your WooCommerce related pages can be named different from the one provide above: just adjust the list to contain the custom names for Woo pages.

Now, let's return to your questions, followed by a comment about the issues you encounter with respect to cache bypassing.

The first question

What is the correct configuration for a wordpress? (I just think that adding / wp-admin / is enough)

is already answered by the fact that you should at least provide a list of various pages that should NOT be cached: it is not enough to "just add /wp-admin".

The second question

Do I have to configure the cookies? I currently have that field empty.

has the answer: yes, otherwise you will get the issue with cache bypasses.


Let's return to the two problems you have.

Problem 1 - two cache related headers: just remove the add_header X-NG-Cache-Status $upstream_cache_status;

Problem 2 - cache bypasses: just find out which cookies are always present and allow caching of them (for instance, Google Analytics _ga cookie can safely be cached, but not all cookies can be cached safely, so be careful and try to prevent cache related security risks).


Hope the above helps a bit.

Kind regards.......
 
@trialotto

Thank you very much for your answer. Below I detail what I did.

1- I have removed: add_header X-NG-Cache-Status $upstream_cache_status;
2- I have added:

/wp-admin/
/xmlrpc.php
/wp-(app|cron|login|register|mail).php (or: 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


3- I have added all cookies to my site. (The ones that google chrome has shown me).

It still does not work for me. Always shows "MISS". Why?.
 
@strelok

I suppose that you have cache-control headers that do not allow serving of cached data:

a) the setting cache-control: private often is a problem: it can cause continuous cache misses,

b) the setting cache-control: must-revalidate can be a problem here, in two ways: (on the one hand) there is the default config of the Nginx based caching functionality in Plesk, which config can be causing a revalidation at every request and (on the other hand) specific expire headers can cause cache misses.

Have a look at this page for further information about cache-control.

In the meantime, try to test whether the cache-control settings are actually the culprit: just add

proxy_ignore_headers Expires Cache-Control;

to "Apache & nginx settings > Additional nginx directives", a link that can be found when opening a domain in Plesk Panel.

In general, Nginx is a proxy and can be used to change the response headers, since Nginx effectively is the intermediate between the client doing the requests and Apache.

For instance, using something like

location ~* \.(htm|html)$ {
expires 14d;
access_log off;
add_header Cache-Control "public";
}

can be added to the "Additional nginx directives" section and that will result in a specific response header with cache-control on "public" and expiration equal to 1 month.

You can use the above location block for testing and analysing the root cause of your problem: after all, when adding the location block, your problem should at least be gone for html files (and for all other static files, the problem should persist......... but you will not really notice that, since modern browsers use browser caching by default).

Just let me know what happens!

Hope the above helps a bit.

Kind regards.........
 
In the "Additional nginx directives" section, I have added what you asked for.
location ~* \.(htm|html)$ {
expires 14d;
access_log off;
add_header Cache-Control "public";
}

proxy_ignore_headers Expires Cache-Control;
Now I do not see the "cache status". no caché.png
 
@strelok,

Something probably happened at request time. You should run this kind of test at least with browser cache disabled.

Regards.........
 
I already tried it without cookies in Google Chrome. The result is the same. I do not know what to try anymore.
 
The "x-cache-status" is not displayed. In order to show that value I need to add:

add_header X-NG-Cache-Status $upstream_cache_status;

The problem is that when I add that line, both appear:

x-cache-status and x-ng-cache-status.

The value that always appears is "MISS". I will leave screenshots with the current settings for you to see.

config-1.png config-2.png config-3.png
 
I have managed to solve the problem. IT SHOULD BE IN THE PLESK DOCUMENTATION. I was a week to place the cache ..

proxy_ignore_headers "Set-Cookie";
proxy_hide_header "Set-Cookie";
 
Back
Top