# Question about the env

**URL:** <https://www.ruby-forum.com/t/question-about-the-env/199007>\
**Category:** NGINX\
**Created:** [November 12, 2010, 8:10am UTC](https://www.ruby-forum.com/t/question-about-the-env/199007 "2010-11-12T08:10:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![okkezSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/85f322/32.png) [@okkezSS](https://www.ruby-forum.com/u/okkezSS)\
**Post date:** [November 12, 2010, 8:10am UTC](https://www.ruby-forum.com/t/question-about-the-env/199007/1 "2010-11-12T08:10:37Z")

</div>

Hey, I noticed that the “env” directive in the main module is not an  
equivalent of “export” in bash or “putenv” in C stdlib. The variables  
defined by “env” seems only can be used by the embeded Perl module,  
right?

The wiki doc for this directive is a little hard to understand. Let’s  
make it simple. In which cases, the variables defined by “env” can be  
considered equivalent to the variables in bash?

Thanks.

Posted at Nginx Forum:

> **[Question about the env](https://forum.nginx.org/read.php?2,150046,150046#msg-150046)**
>
> Hey, I noticed that the "env" directive in the main module is not an equivalent of "export" in bash or "putenv" in C stdlib. The variables defined by "env" seems only can be used by the embeded Perl module,...

---

<div class="post-metadata">

**Author:** ![speedfirst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e19adc/32.png) [@speedfirst](https://www.ruby-forum.com/u/speedfirst)\
**Post date:** [November 12, 2010, 8:19pm UTC](https://www.ruby-forum.com/t/question-about-the-env/199007/2 "2010-11-12T20:19:43Z")

</div>

On Fri, Nov 12, 2010 at 02:09:11AM -0500, speedfirst wrote:

> Hey, I noticed that the “env” directive in the main module is not an  
> equivalent of “export” in bash or “putenv” in C stdlib. The variables  
> defined by “env” seems only can be used by the embeded Perl module,  
> right?

Not only.  
For example, “env OPENSSL\_ALLOW\_PROXY\_CERTS=1;” controls OpenSSL.  
“env MALLOC\_OPTIONS;” controls FreeBSD malloc().

> The wiki doc for this directive is a little hard to understand. Let’s  
> make it simple. In which cases, the variables defined by “env” can be  
> considered equivalent to the variables in bash?

By default, nginx wipes all its environment variables expect TZ  
variable.  
“env NAME” allows to keep NAME variable value got from parent process,  
i.e., shell. “env NAME=val” sets NAME variable value.

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![speedfirst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e19adc/32.png) [@speedfirst](https://www.ruby-forum.com/u/speedfirst)\
**Post date:** [November 12, 2010, 8:45pm UTC](https://www.ruby-forum.com/t/question-about-the-env/199007/3 "2010-11-12T20:45:29Z")

</div>

On Fri, Nov 12, 2010 at 10:18:54PM +0300, Igor S. wrote:

> On Fri, Nov 12, 2010 at 02:09:11AM -0500, speedfirst wrote:
> 
> > Hey, I noticed that the “env” directive in the main module is not an  
> > equivalent of “export” in bash or “putenv” in C stdlib. The variables  
> > defined by “env” seems only can be used by the embeded Perl module,  
> > right?
> 
> Not only.  
> For example, “env OPENSSL\_ALLOW\_PROXY\_CERTS=1;” controls OpenSSL.  
> “env MALLOC\_OPTIONS;” controls FreeBSD malloc().

However, setting FreeBSD MALLOC\_OPTIONS using “env” is useless, because  
malloc() analyzes MALLOC\_OPTIONS on the very start before event main()  
is called. Nevertheless “env MALLOC\_OPTIONS;” is useful during online  
upgrade: a new nginx is run with inherited MALLOC\_OPTIONS.

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![speedfirst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e19adc/32.png) [@speedfirst](https://www.ruby-forum.com/u/speedfirst)\
**Post date:** [November 13, 2010, 12:53pm UTC](https://www.ruby-forum.com/t/question-about-the-env/199007/4 "2010-11-13T12:53:31Z")

</div>

I carefully read the code of “ngx\_set\_env” and “ngx\_set\_environment”.  
And I found that once “ngx\_set\_environment” is invoked, the arguments of  
“env” directive is put into “envrion”, which makes those variables  
effective.

However, this works well only when ngx\_set\_environment is invoked. And  
ngx\_set\_environment will be invoked only when new worker process is  
initiated. But in the developement/debug mode (daemon off,  
master\_process off), the variables will never be put into environ, which  
may incur some inconsistent bug when nginx is running in dev mode and  
production mode.

Therefore, I think this is a bug.

Posted at Nginx Forum:

> **[Re: Question about the env](https://forum.nginx.org/read.php?2,150046,150461#msg-150461)**
>
> Hey, I noticed that the "env" directive in the main module is not an equivalent of "export" in bash or "putenv" in C stdlib. The variables defined by "env" seems only can be used by the embeded Perl module,...
