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

Jelle de Jong jelledejong at powercraft.nl
Mon Jan 24 09:57:17 UTC 2022


Thank you for taking a look!

On 1/24/22 00:45, Francis Daly wrote:
> 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.

I want to be able to do an redirect, but only one time, the hit it 
should not redirect.

If a client visits an web-store it will get redirected to the region 
specific store, but if then then manually select an other store there it 
should not redirect back again. I don't know if a nginx session cookie 
is possible or an way to use the nginx upstream module?

I am open to ideas to make this work.

Kind regards,

Jelle de Jong



More information about the nginx mailing list