# Question about the context of map directive

**URL:** <https://www.ruby-forum.com/t/question-about-the-context-of-map-directive/206561>\
**Category:** NGINX\
**Created:** [May 4, 2011, 9:00pm UTC](https://www.ruby-forum.com/t/question-about-the-context-of-map-directive/206561 "2011-05-04T21:00:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [May 4, 2011, 9:00pm UTC](https://www.ruby-forum.com/t/question-about-the-context-of-map-directive/206561/1 "2011-05-04T21:00:01Z")

</div>

Hi,

The context of map directive is _http_ as documented on [wiki.nginx.org](http://wiki.nginx.org).  
This  
means all the requests will go through the map filter phase.  
This is not ideal when you have many virtual hosts.

For example, we’ve 50+ virtual hosts. When one of them need map  
variables,  
the others automatically inherited those settings because there is no  
way to  
limit it to server context.

If this is the situation, can someone know the internals of nginx  
explain  
why the map module can’t work at server level.  
Thanks.

---

<div class="post-metadata">

**Author:** ![SSSSSSS\_SS\_SSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/91b2a8/32.png) [@SSSSSSS\_SS\_SSS](https://www.ruby-forum.com/u/SSSSSSS_SS_SSS)\
**Post date:** [May 4, 2011, 9:10pm UTC](https://www.ruby-forum.com/t/question-about-the-context-of-map-directive/206561/2 "2011-05-04T21:10:31Z")

</div>

On Thu, May 05, 2011 at 02:59:21AM +0800, 杨镭 wrote:

> If this is the situation, can someone know the internals of nginx explain  
> why the map module can’t work at server level.  
> Thanks.

The most nginx directives are declarative. This means that nginx  
looks up a map only when it needs a variable value defined via the map.  
There are directives that are really executed: “rewrite” and “if”.  
Avoid them.

–  
Igor S.

---

<div class="post-metadata">

**Author:** ![SSSSSSS\_SS\_SSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/91b2a8/32.png) [@SSSSSSS\_SS\_SSS](https://www.ruby-forum.com/u/SSSSSSS_SS_SSS)\
**Post date:** [May 4, 2011, 9:16pm UTC](https://www.ruby-forum.com/t/question-about-the-context-of-map-directive/206561/3 "2011-05-04T21:16:06Z")

</div>

On Wed, May 04, 2011 at 11:10:00PM +0400, Igor S. wrote:

> > If this is the situation, can someone know the internals of nginx explain  
> > why the map module can’t work at server level.  
> > Thanks.
> 
> The most nginx directives are declarative. This means that nginx  
> looks up a map only when it needs a variable value defined via the map.  
> There are directives that are really executed: “rewrite” and “if”.  
> Avoid them.

Also “set” and “break”.

–  
Igor S.

---

<div class="post-metadata">

**Author:** ![SSSSSSS\_SS\_SSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/91b2a8/32.png) [@SSSSSSS\_SS\_SSS](https://www.ruby-forum.com/u/SSSSSSS_SS_SSS)\
**Post date:** [May 4, 2011, 10:36pm UTC](https://www.ruby-forum.com/t/question-about-the-context-of-map-directive/206561/4 "2011-05-04T22:36:29Z")

</div>

Hello!

On Thu, May 05, 2011 at 02:59:21AM +0800, 杨镭 wrote:

> Hi,
> 
> The context of map directive is _http_ as documented on [wiki.nginx.org](http://wiki.nginx.org). This

Yes.

> means all the requests will go through the map filter phase.

No. Map directive creates a variable and only does something when  
(and if) the variable is accessed. There is no performance  
penalty for processing requests which doesn’t use the variable.

> This is not ideal when you have many virtual hosts.
> 
> For example, we’ve 50+ virtual hosts. When one of them need map variables,  
> the others automatically inherited those settings because there is no way to  
> limit it to server context.
> 
> If this is the situation, can someone know the internals of nginx explain  
> why the map module can’t work at server level.

Changing map module to provide data based on per-server configs is  
possible, but obviously will require extra code.

Maxim D.

---

<div class="post-metadata">

**Author:** ![SSSSSSS\_SS\_SSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/91b2a8/32.png) [@SSSSSSS\_SS\_SSS](https://www.ruby-forum.com/u/SSSSSSS_SS_SSS)\
**Post date:** [May 5, 2011, 4:15am UTC](https://www.ruby-forum.com/t/question-about-the-context-of-map-directive/206561/5 "2011-05-05T04:15:45Z")

</div>

Hi Igor and Maxim,

Thanks for the reply!
