• 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.

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