Hello!
I’ve got beta and live site listening on different ip on the same
server. Both sites using same ‘if’ in ‘server’ statement:
server {
listen 1.1.1.1:80;
server_name live;
set $mage_run_code default;
if ($cookie_store_code = a1) {
set $mage_run_code kiosk_a1;
}
if ($cookie_store_code = b2) {
set $mage_run_code kiosk1_b2;
}
if ($cookie_store_code = c3) {
set $mage_run_code kiosk2_c3;
}
}
server {
listen 2.2.2.2:80;
server_name live;
set $mage_run_code default;
if ($cookie_store_code = a1) {
set $mage_run_code kiosk_a1;
}
if ($cookie_store_code = b2) {
set $mage_run_code kiosk1_b2;
}
if ($cookie_store_code = c3) {
set $mage_run_code kiosk2_c3;
}
}
I want to replace if with map. Changes seem obvious:
map $cookie_store_code $mage_run_code_live {
default default;
a1 kiosk_a1;
b2 kiosk1_b2;
c3 kiosk2_c3;
}
map $cookie_store_code $mage_run_code_beta {
default default;
a1 kiosk_a1;
b2 kiosk1_b2;
c3 kiosk2_c3;
}
server {
listen 1.1.1.1:80;
server_name live;
set $mage_run_code $mage_run_code_live;
}
server {
listen 2.2.2.2:80;
server_name beta;
set $mage_run_code $mage_run_code_beta;
}
The only thing disquiets me in this solution: 'if’s are in ‘server’
statement and ‘map’ has a global context ‘http’. So, does setting cookie
for beta site have any impacts on live site and vice versa? Or this
solution provides independence of working live and beta regarding
setting cookies?
Found in agentzh's Nginx Tutorials (version 2020.03.19)
even though the scope of Nginx variables is the entire configuration,
each request does have its own version of all those variables’
containers. Requests do not interfere with each other even if they are
referencing a variable with the same name. This is very much like local
variables in C/C++ function bodies. Each invocation of the C/C++
function does use its own version of those local variables (on the
stack).