# Regarding setting ENV variable

**URL:** <https://www.ruby-forum.com/t/regarding-setting-env-variable/217653>\
**Category:** NGINX\
**Created:** [March 7, 2012, 6:07pm UTC](https://www.ruby-forum.com/t/regarding-setting-env-variable/217653 "2012-03-07T18:07:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [March 7, 2012, 6:07pm UTC](https://www.ruby-forum.com/t/regarding-setting-env-variable/217653/1 "2012-03-07T18:07:49Z")

</div>

Hi Friends  
I want to set a env variable on nginx with perl whenever  
i am accessing site with https only. can anyone help how i can do this.  
I looked at post env variable in nginx.conf file it didnt help me.Is  
there any way that i can set environment variable using mod\_perl.

thanks

Posted at Nginx Forum:

> **[Regarding setting ENV variable](https://forum.nginx.org/read.php?2,223590,223590#msg-223590)**
>
> Hi Friends I want to set a env variable on nginx with perl whenever i am accessing site with https only. can anyone help how i can do this. I looked at post env variable in nginx.conf file it didnt help me.Is there any way that i can set environment...

---

<div class="post-metadata">

**Author:** ![shivnamha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cc9497/32.png) [@shivnamha](https://www.ruby-forum.com/u/shivnamha)\
**Post date:** [March 7, 2012, 6:14pm UTC](https://www.ruby-forum.com/t/regarding-setting-env-variable/217653/2 "2012-03-07T18:14:02Z")

</div>

On 3/7/12, shivnamha [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi Friends  
> I want to set a env variable on nginx with perl whenever  
> i am accessing site with https only. can anyone help how i can do this.  
> I looked at post env variable in nginx.conf file it didnt help me.Is  
> there any way that i can set environment variable using mod\_perl.

Are you sure that’s what you need? You can pass $https with  
fastcgi\_param or access it with perl’s variable method:  
$r-\>variable(‘https’) and set $ENV{..} accordingly.

---

<div class="post-metadata">

**Author:** ![shivnamha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cc9497/32.png) [@shivnamha](https://www.ruby-forum.com/u/shivnamha)\
**Post date:** [March 8, 2012, 7:07am UTC](https://www.ruby-forum.com/t/regarding-setting-env-variable/217653/3 "2012-03-08T07:07:56Z")

</div>

Hi Alexandr  
Thanks Alexander.But I didnt get u completly. I tried  
by adding a ‘fastcgi\_param HTTPS on;’ but this variable is getting  
set for http request as well for https request. But i need to set for  
https request. Can u please elaborate ur statement so that i can easily  
understand it.

Posted at Nginx Forum:

> **[Re: Regarding setting ENV variable](https://forum.nginx.org/read.php?2,223590,223620#msg-223620)**
>
> Hi Friends I want to set a env variable on nginx with perl whenever i am accessing site with https only. can anyone help how i can do this. I looked at post env variable in nginx.conf file it didnt help me.Is there any way that i can set environment...

---

<div class="post-metadata">

**Author:** ![shivnamha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cc9497/32.png) [@shivnamha](https://www.ruby-forum.com/u/shivnamha)\
**Post date:** [March 8, 2012, 6:20pm UTC](https://www.ruby-forum.com/t/regarding-setting-env-variable/217653/4 "2012-03-08T18:20:06Z")

</div>

thanks allot Valentin and Alexandr . It really helpful for me…

Posted at Nginx Forum:

> **[Re: Regarding setting ENV variable](https://forum.nginx.org/read.php?2,223590,223637#msg-223637)**
>
> Hi Friends I want to set a env variable on nginx with perl whenever i am accessing site with https only. can anyone help how i can do this. I looked at post env variable in nginx.conf file it didnt help me.Is there any way that i can set environment...

---

<div class="post-metadata">

**Author:** ![shivnamha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cc9497/32.png) [@shivnamha](https://www.ruby-forum.com/u/shivnamha)\
**Post date:** [March 8, 2012, 12:47pm UTC](https://www.ruby-forum.com/t/regarding-setting-env-variable/217653/5 "2012-03-08T12:47:34Z")

</div>

On Thursday 08 March 2012 10:07:35 shivnamha wrote:

> Hi Alexandr  
> Thanks Alexander.But I didnt get u completly. I tried  
> by adding a ‘fastcgi\_param HTTPS on;’ but this variable is getting  
> set for http request as well for https request. But i need to set for  
> https request. Can u please elaborate ur statement so that i can easily  
> understand it.

[http://nginx.org/en/docs/http/ngx\_http\_core\_module.html#variables](http://nginx.org/en/docs/http/ngx_http_core_module.html#variables)

```
fastcgi_param HTTPS $https if_not_empty; # for NGINX >= 1.1.11

```

For NGINX \< 1.1.11:

```
map $scheme $https_on {
    default '';
    https on;
}

fastcgi_param HTTPS $https_on;

```

> **[Module ngx\_http\_fastcgi\_module](http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_param)**
>
> The ngx\_http\_fastcgi\_module module allows passing requests to a FastCGI server.

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

wbr, Valentin V. Bartenev
