# Why will nginx's map directive eat all ram?

**URL:** <https://www.ruby-forum.com/t/why-will-nginxs-map-directive-eat-all-ram/245941>\
**Category:** NGINX\
**Created:** [August 2, 2013, 2:30pm UTC](https://www.ruby-forum.com/t/why-will-nginxs-map-directive-eat-all-ram/245941 "2013-08-02T14:30:52Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [August 2, 2013, 2:30pm UTC](https://www.ruby-forum.com/t/why-will-nginxs-map-directive-eat-all-ram/245941/1 "2013-08-02T14:30:52Z")

</div>

recently I try to use map directive to make my nginx.conf DRY. like  
below

`map $pid $public_root { default public; }`

and in one of server directive I put below

`root $public_root;`

I try to `ab` test with retrieve a static html. the nginx will eat all  
ram.  
if I reset back to `root public;` it will maintain the ram in low evel.

so we should avoid to use map directive ?

My Env: MACOSX 10.8.4, Nginx 1.4.1

Posted at Nginx Forum:

> **[why will nginx's map directive eat all ram?](https://forum.nginx.org/read.php?2,241478,241478#msg-241478)**
>
> recently I try to use map directive to make my nginx.conf DRY. like below \`map $pid $public\_root { default public; }\` and in one of server directive I put below \`root $public\_root;\` I try to \`ab\` test with retrieve a static html. the nginx

---

<div class="post-metadata">

**Author:** ![Payne\_Chu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/96bed5/32.png) [@Payne\_Chu](https://www.ruby-forum.com/u/Payne_Chu)\
**Post date:** [August 2, 2013, 5:06pm UTC](https://www.ruby-forum.com/t/why-will-nginxs-map-directive-eat-all-ram/245941/2 "2013-08-02T17:06:18Z")

</div>

On Friday 02 August 2013 16:30:35 Payne Chu wrote:

> so we should avoid to use map directive ?
> 
> My Env: MACOSX 10.8.4, Nginx 1.4.1

What does “nginx -V” show?

wbr, Valentin V. Bartenev

–

> **[nginx: donation](http://nginx.org/en/donation.html)**

---

<div class="post-metadata">

**Author:** ![Payne\_Chu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/96bed5/32.png) [@Payne\_Chu](https://www.ruby-forum.com/u/Payne_Chu)\
**Post date:** [August 3, 2013, 4:09am UTC](https://www.ruby-forum.com/t/why-will-nginxs-map-directive-eat-all-ram/245941/3 "2013-08-03T04:09:16Z")

</div>

here it is

nginx version: ngx\_openresty/1.4.1.1  
TLS SNI support enabled  
configure arguments: --prefix=/usr/local/openresty/nginx  
–with-cc-opt=‘-I/usr/local/Cellar/pcre/8.33/include  
-I/usr/local/Cellar/luajit/2.02/luajit2.0/include’  
–add-module=…/ngx\_devel\_kit-0.2.18  
–add-module=…/echo-nginx-module-0.45  
–add-module=…/xss-nginx-module-0.03rc9  
–add-module=…/ngx\_coolkit-0.2rc1  
–add-module=…/set-misc-nginx-module-0.22rc8  
–add-module=…/form-input-nginx-module-0.07  
–add-module=…/encrypted-session-nginx-module-0.03  
–add-module=…/srcache-nginx-module-0.21 --add-module=…/ngx\_lua-0.8.5  
–add-module=…/headers-more-nginx-module-0.21  
–add-module=…/array-var-nginx-module-0.03rc1  
–add-module=…/memc-nginx-module-0.13rc3  
–add-module=…/redis2-nginx-module-0.10  
–add-module=…/redis-nginx-module-0.3.6  
–add-module=…/auth-request-nginx-module-0.2  
–add-module=…/rds-json-nginx-module-0.12rc10  
–add-module=…/rds-csv-nginx-module-0.05rc2  
–with-ld-opt=‘-Wl,-rpath,/usr/local/openresty/luajit/lib  
-L/usr/local/Cellar/pcre/8.33/lib  
-L/usr/local/Cellar/luajit/2.02/luajit2.0/lib’  
–http-client-body-temp-path=/var/tmp/nginx/client\_body  
–http-proxy-temp-path=/var/tmp/nginx/proxy  
–http-fastcgi-temp-path=/var/tmp/nginx/fastcgi  
–http-uwsgi-temp-path=/var/tmp/nginx/uwsgi  
–http-scgi-temp-path=/var/tmp/nginx/scgi --with-http\_ssl\_module

Actually Im using OpenResty. But since OpenResty said it’s just standard  
nginx. and in config I not even active any lua directive yet. so I  
thought  
this should the nginx probelm. But when I install nginx-1.4.1 through  
`Homebrew`. I cannot find same issue in the brew version. Maybe just one  
of  
OpenResty used module trigger this. below is the config trigger this  
issue.  
And let me know if I need to forward this issue to OpenResty. Thanks 🙂

user paynechu staff;  
worker\_processes 1;

events {  
worker\_connections 1024;  
}

http {

map $pid $public\_root { default public; }

server {  
listen 443;  
index index.html;  
ssl on;  
ssl\_certificate ssl/sandbox.crt;  
ssl\_certificate\_key ssl/sandbox.key;  
ssl\_session\_timeout 5m;  
ssl\_protocols SSLv2 SSLv3 TLSv1;  
ssl\_ciphers HIGH:!aNULL:!MD5;  
ssl\_prefer\_server\_ciphers on;  
root $public\_root;  
}  
}

Posted at Nginx Forum:

> **[Re: why will nginx's map directive eat all ram?](https://forum.nginx.org/read.php?2,241478,241499#msg-241499)**
>
> recently I try to use map directive to make my nginx.conf DRY. like below \`map $pid $public\_root { default public; }\` and in one of server directive I put below \`root $public\_root;\` I try to \`ab\` test with retrieve a static html. the nginx

---

<div class="post-metadata">

**Author:** ![Payne\_Chu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/96bed5/32.png) [@Payne\_Chu](https://www.ruby-forum.com/u/Payne_Chu)\
**Post date:** [August 3, 2013, 10:42am UTC](https://www.ruby-forum.com/t/why-will-nginxs-map-directive-eat-all-ram/245941/4 "2013-08-03T10:42:22Z")

</div>

[https://groups.google.com/forum/#!topic/openresty-en/ArNhoL7Ol2U](https://groups.google.com/forum/#!topic/openresty-en/ArNhoL7Ol2U)

here is the reply from OpenResty’s agentzh.

seems the leak come from nginx 1.4.1’s core. Maybe Homebrew have some  
patch  
fixed this issue ?

Posted at Nginx Forum:

> **[Re: why will nginx's map directive eat all ram?](https://forum.nginx.org/read.php?2,241478,241502#msg-241502)**
>
> recently I try to use map directive to make my nginx.conf DRY. like below \`map $pid $public\_root { default public; }\` and in one of server directive I put below \`root $public\_root;\` I try to \`ab\` test with retrieve a static html. the nginx

---

<div class="post-metadata">

**Author:** ![Payne\_Chu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/96bed5/32.png) [@Payne\_Chu](https://www.ruby-forum.com/u/Payne_Chu)\
**Post date:** [August 3, 2013, 11:58am UTC](https://www.ruby-forum.com/t/why-will-nginxs-map-directive-eat-all-ram/245941/5 "2013-08-03T11:58:19Z")

</div>

Finally I can reproduce even in the Homebrew version. It will only leak  
when  
I use relative path. and all version also can reproduce. b4 I test  
Homebrew  
version with full path not relative path that’s the different…XD~

map $pid $public\_root { default public; } ← this one relative path  
leak happened  
map $pid $public\_root { default /usr/local/Cellar/nginx/1.4.1/public; }  
 ←   
this one full path without leak…

Posted at Nginx Forum:

> **[Re: why will nginx's map directive eat all ram?](https://forum.nginx.org/read.php?2,241478,241503#msg-241503)**
>
> recently I try to use map directive to make my nginx.conf DRY. like below \`map $pid $public\_root { default public; }\` and in one of server directive I put below \`root $public\_root;\` I try to \`ab\` test with retrieve a static html. the nginx

---

<div class="post-metadata">

**Author:** ![Payne\_Chu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/96bed5/32.png) [@Payne\_Chu](https://www.ruby-forum.com/u/Payne_Chu)\
**Post date:** [August 3, 2013, 12:09pm UTC](https://www.ruby-forum.com/t/why-will-nginxs-map-directive-eat-all-ram/245941/6 "2013-08-03T12:09:25Z")

</div>

On Saturday 03 August 2013 06:08:43 Payne Chu wrote:

> –add-module=../form-input-nginx-module-0.07  
> –with-ld-opt=‘-Wl,-rpath,/usr/local/openresty/luajit/lib  
> -L/usr/local/Cellar/pcre/8.33/lib  
> -L/usr/local/Cellar/luajit/2.02/luajit2.0/lib’  
> –http-client-body-temp-path=/var/tmp/nginx/client\_body  
> –http-proxy-temp-path=/var/tmp/nginx/proxy  
> –http-fastcgi-temp-path=/var/tmp/nginx/fastcgi  
> –http-uwsgi-temp-path=/var/tmp/nginx/uwsgi  
> –http-scgi-temp-path=/var/tmp/nginx/scgi --with-http\_ssl\_module
> 
> Actually Im using OpenResty. But since OpenResty said it’s just standard  
> nginx.

No, any nginx with 3-rd party modules (“–add-module” arguments in your  
“nginx -V” output) isn’t standard. Even if such modules do not used in  
config, they still can affect behavior in strange ways.

> and in config I not even active any lua directive yet. so I thought  
> this should the nginx probelm. But when I install nginx-1.4.1 through  
> `Homebrew`. I cannot find same issue in the brew version. Maybe just one of  
> OpenResty used module trigger this. below is the config trigger this issue.  
> And let me know if I need to forward this issue to OpenResty. Thanks 🙂

[…]

Yes, you should forward this issue to OpenResty, since you can’t  
reproduce  
it without 3-rd party code, and there are no known problems with the map  
directive memory consumption.

wbr, Valentin V. Bartenev

–

> **[nginx: donation](http://nginx.org/en/donation.html)**

---

<div class="post-metadata">

**Author:** ![Payne\_Chu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/96bed5/32.png) [@Payne\_Chu](https://www.ruby-forum.com/u/Payne_Chu)\
**Post date:** [August 3, 2013, 12:16pm UTC](https://www.ruby-forum.com/t/why-will-nginxs-map-directive-eat-all-ram/245941/7 "2013-08-03T12:16:26Z")

</div>

On Saturday 03 August 2013 14:08:50 Valentin V. Bartenev wrote:  
[…]

> it without 3-rd party code, and there are no known problems with the map  
> directive memory consumption.

Please disregard this statement, I’ve just received your last messages.

I’m going to look at this issue, thank you for the report.

wbr, Valentin V. Bartenev

–

> **[nginx: donation](http://nginx.org/en/donation.html)**

---

<div class="post-metadata">

**Author:** ![Payne\_Chu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/96bed5/32.png) [@Payne\_Chu](https://www.ruby-forum.com/u/Payne_Chu)\
**Post date:** [August 4, 2013, 2:40am UTC](https://www.ruby-forum.com/t/why-will-nginxs-map-directive-eat-all-ram/245941/8 "2013-08-04T02:40:31Z")

</div>

On Saturday 03 August 2013 13:57:52 Payne Chu wrote:

> Finally I can reproduce even in the Homebrew version. It will only leak  
> when I use relative path. and all version also can reproduce. b4 I test  
> Homebrew version with full path not relative path that’s the  
> different…XD~
> 
> map $pid $public\_root { default public; } ← this one relative path  
> leak happened  
> map $pid $public\_root { default /usr/local/Cellar/nginx/1.4.1/public; } ←   
> this one full path without leak..

Please, try this patch:  
[http://pp.nginx.com/vbart/patches/fix\_memleak.txt](http://pp.nginx.com/vbart/patches/fix_memleak.txt)  
It fixes the leak.

wbr, Valentin V. Bartenev

–

> **[nginx: donation](http://nginx.org/en/donation.html)**

---

<div class="post-metadata">

**Author:** ![Payne\_Chu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/96bed5/32.png) [@Payne\_Chu](https://www.ruby-forum.com/u/Payne_Chu)\
**Post date:** [August 5, 2013, 5:17am UTC](https://www.ruby-forum.com/t/why-will-nginxs-map-directive-eat-all-ram/245941/9 "2013-08-05T05:17:52Z")

</div>

Thanks Valentin,

The issue fixed

Posted at Nginx Forum:

> **[Re: why will nginx's map directive eat all ram?](https://forum.nginx.org/read.php?2,241478,241566#msg-241566)**
>
> recently I try to use map directive to make my nginx.conf DRY. like below \`map $pid $public\_root { default public; }\` and in one of server directive I put below \`root $public\_root;\` I try to \`ab\` test with retrieve a static html. the nginx
