Welcome! Log In Create A New Profile

Advanced

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

Reinis Rozitis
January 24, 2022 12:20PM
> I got it working! I am not sure of the performance hit, maybe someone know
how to make this more effective?

Without going deeper on what are your actual requirements and what is the
expected result, the suggestion I could give is instead of the multiple if
statements to look at the map directive
(http://nginx.org/en/docs/http/ngx_http_map_module.html ) - it is more
powerful and performant.

For example all the $geoip2_data_country_iso ifs could be:

map $geoip2_data_country_iso_code $MAGE_RUN_CODE_ORG {
NL storeview07;
US storeview08;
DE storeview09;

// optionally a default which will be set for all non-matching country
codes
}

Since you can also chain the map directives the same probably can be done
with the $redirect logic - rather than multiple ifs you could group the
checks for same conditions together.. but I'm not exactly sure I understand
the reason behind the /noredirect/ location and rewriting:

if ($request_uri ~ "^/(noredirect)/(.*)$" ) {
set $redirect false;
}
location ~ ^/(noredirect)/ {
add_header Set-Cookie
"REDIRECT=false;Domain=$host;Path=/;Max-Age=31536000";
rewrite ^/noredirect(.*)$ https://$host$1 redirect;
}

Some thoughts:

- if you have already a location match the if check (for the same uri) is
redundant you could just set the variable in the location block
- extracting regexp parts of the without using them makes little sense -
since you do rewrite ^/noredirect(.*)$ https://$host$1 redirect; the
"^/(noredirect)/(.*)$" and ~ ^/(noredirect)/ is not needed - just using
location ^~ /noredirect or location ~ ^/noredirect (depending on the
location match priority) would be enough
- in the end in one location check $redirect is being set to false and then
in in the same location still a redirect happens is confusing (at least) to
me


p.s. sometimes writing the application logic in pure webserver configuration
is cumbersome - dynamic languages like Lua (can be embedded in nginx) / Perl
or php could do a better job.

rr

_______________________________________________
nginx mailing list -- nginx@nginx.org
To unsubscribe send an email to nginx-leave@nginx.org
Subject Author Posted

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

Jelle de Jong January 21, 2022 06:50AM

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

Francis Daly January 23, 2022 06:50PM

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

Jelle de Jong January 24, 2022 05:02AM

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

Reinis Rozitis January 24, 2022 05:20AM

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

Jelle de Jong January 24, 2022 10:14AM

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

Reinis Rozitis January 24, 2022 12:20PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 88
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