using same cookie in map for 2 independent sites

Aleksey Portnov a.portnov at ism-ukraine.com
Wed Apr 15 09:40:52 UTC 2015


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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20150415/e0139f0c/attachment.html>


More information about the nginx mailing list