how to create session persistence or hash_ip within server context for an if statement

Francis Daly francis at daoine.org
Sun Jan 23 23:45:08 UTC 2022


On Fri, Jan 21, 2022 at 12:45:16PM +0100, Jelle de Jong wrote:

Hi there,

> How can I use an nginx session or hash_ip in the server context to only do
> the following if statement code once and not a second time an client visits
> the website:
> 
> server {
>     if ($geoip2_data_country_iso_code != GB) {
>         return 302 https://test01.example.nl$request_uri;
>     }
> }
> 
> I want the above code to be executed only once, and then be remembered for
> the next 24 hours or so (this is flexible, not a hard requirement).

For what I think you are asking for, I think the answer is a combination
of "stock nginx does not let you cache at that level"; and "it should
not matter; that lookup should be lightweight".

But I'm not quite sure what you are asking for; or why you are asking
for it. So maybe there's a different answer too.

Cheers,

	f
-- 
Francis Daly        francis at daoine.org



More information about the nginx mailing list