Nginx Map Directive for multiple variables

Alex Block asked:

I currently use nginx with Magento and I use the map directive to supply the store code like this:

map $http_host $magecode {
        www.store.com retail_store;
        wholesale.store.com wholesale_store;
        beta.store.com retail_beta_view;
}

The drawback to this is if I make the beta site its own store, I can’t use the same catalog. Instead, I want to make the beta site a website instead of store.

Is it possible to map two variables at a time? I am imagining it would look like this:

map $http_host $magecode $magetype {
        www.store.com retail_store website;
        wholesale.store.com wholesale_store website;
        beta.store.com retail_beta_view store;
}

If not can I map the same variable twice?

map $http_host $magecode { ... }
map $http_host $magetype { ... }

My answer:


Yes, you can use more than one map and that seems to be the cleanest way to solve this.

map $http_host $magecode {
        www.store.com retail_store;
        wholesale.store.com wholesale_store;
        beta.store.com retail_beta_view;
}

map $http_host $magetype {
        www.store.com website;
        wholesale.store.com website;
        beta.store.com store;
}

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.