Welcome! Log In Create A New Profile

Advanced

using same cookie in map for 2 independent sites

Aleksey Portnov
April 15, 2015 05:42AM
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 http://openresty.org/download/agentzh-nginx-tutorials-en.html
---------------------
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).
---------------------
Can someone approve it? It it's true my config is correct.

--
Sincerely yours,

Aleksey Portnov | System Administrator | ISM eCompany | T +38 098 92 32 432

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

using same cookie in map for 2 independent sites

Aleksey Portnov April 15, 2015 05:42AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 88
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready