Welcome! Log In Create A New Profile

Advanced

Skip cache based on upstream response, not client request

January 17, 2024 07:35AM
So, I have following settings, related to caching:
------------------------------------------------
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
------------------------------------------------

And set of rules which are skipping cache, like
------------------------------------------------
if ($request_uri ~* "(\.well-known|acme-challenge)") {
set $skip_cache 1;
set $skip_cache_reason " - Rule2";
}
------------------------------------------------

The problem is that PHP sometimes returns wrong 301 redirect create, with wrong location, which looks like:
------------------------------------------------
HTTP/2 301
server: nginx
date: Wed, 17 Jan 2024 11:46:41 GMT
content-type: text/html; charset=UTF-8
location: https:///
x-cache-status: HIT
....
------------------------------------------------

While we're trying to find and fix the root cause I'd like to skip caching for such type of answers.
AFAIK 'if' works only before sending to upstream, so I can't just use something like 'if ($upstream_http_location = "https:///")'
I was going to create LUA script for checking that, but not sure into which phase I can add it, like which directive to use 'access_by_lua_file' or maybe 'log_by_lua_file', etc.
I also suspect there could not exist 'correct' LUA derictive for that as such procession could happen even before generating response.
So, is there any way to not cache based on upstream response?
Subject Author Posted

Skip cache based on upstream response, not client request

KitPavloNaMopedi January 17, 2024 07:35AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 132
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready