• 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 disable nginx caching status 302?

Redsector

New Pleskian
Server operating system version
Ubuntu 20.04.6 LTS
Plesk version and microupdate number
Plesk Obsidian 18.0.51 Update #1
I have a website that "detects" browser language when is invoked directly and redirect accordingly to the proper language.
I have found out that if I "Enable nginx caching" it will cache this redirect. What happens is taht any following request from anyone/anywhere else, will be redirected to the "first" user language even if is different.

To debug I use:
curl -Ls -H 'Accept-Language: XX' -I https://www.website.tld
and I see x-cache-status: HIT except the first time.

I've tried adding some directives but none seems to works.

proxy_cache_valid 302 0;
proxy_no_cache $http_response_status 302;
proxy_cache_bypass $http_response_status 302;

Is there any way to avoid this caching behavior?
 
You can try to add this directive block to additional Nginx directives:
Code:
if ($request_uri ~* "(/)") {
 set $skip_cache 1;
 set $skip_reason "${skip_reason}-request_uri";
}
Not tested, theoretical solution
 
Hi @Peter Debik,
I've tried your suggestion but it still caches.

Here is a request with language "us"

HTTP/2 302
server: nginx
date: Tue, 18 Apr 2023 17:12:49 GMT
content-type: text/html; charset=iso-8859-1
content-length: 225
location: https://XXX/de/index.html
cache-control: max-age=600
expires: Tue, 18 Apr 2023 17:22:42 GMT
x-cache-status: HIT
 
The location string is different in your test. There it is
/de/index.html
but in the directive it is
/
The question here is what the original request is that is sent to your server. Is it addressing / or is it directly addressing /de/index.html?
 
This redirect is working only if someone request the "domain", without any page, else is disregarded.
First I change from http to https, then i redirect according to language to /LANGUAGE/index.html
 
I think your above example only shows that the /de/index.html page is cached, not that the / path is cached. Have you also added a no-cache policy to the index page of the website so that the browser does not cache the request? Else it is well possible that your redirect is not initialized by a cached Nginx page, but by the browser.

For details on how to exlude specific pages from Nginx caching I found this guide that in my opinion covers it all:
 
I have a website that "detects" browser language when is invoked directly and redirect accordingly to the proper language.
I have found out that if I "Enable nginx caching" it will cache this redirect. What happens is taht any following request from anyone/anywhere else, will be redirected to the "first" user language even if is different.

To debug I use:
curl -Ls -H 'Accept-Language: XX' -I https://www.website.tld
and I see x-cache-status: HIT except the first time.

I've tried adding some directives but none seems to works.

proxy_cache_valid 302 0;
proxy_no_cache $http_response_status 302;
proxy_cache_bypass $http_response_status 302;

Is there any way to avoid this caching behavior?
It must be very convenient.
 
Hi Peter, thanks for the assistance.
the issue is that the redirect is not for a "page". Technically speaking is for an URL.
If I do exclude the destination page (after the redirect) the redirect is still cached. If I do exclude "/", then the whole website is excluded.
 
Back
Top