# $https variable?

**URL:** <https://www.ruby-forum.com/t/https-variable/212172>\
**Category:** NGINX\
**Created:** [September 24, 2011, 9:13am UTC](https://www.ruby-forum.com/t/https-variable/212172 "2011-09-24T09:13:25Z")\
**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:** [September 24, 2011, 9:13am UTC](https://www.ruby-forum.com/t/https-variable/212172/1 "2011-09-24T09:13:25Z")

</div>

It would be great if there was an $https variable that was “on” or “off”  
(or “”) so you could do something like this:

fastcgi\_param HTTPS $https;

Because currently telling PHP https is enabled is much harder,  
especially for those that prefer to have a single server{} block for  
both HTTP and HTTPS.

Typically PHP uses $\_SERVER[‘HTTPS’] === ‘on’ to detect whether or not  
HTTPS is enabled.

[http://us3.php.net/manual/en/reserved.variables.server.php](http://us3.php.net/manual/en/reserved.variables.server.php)

Luke

---

<div class="post-metadata">

**Author:** ![Luke\_Scott](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/d2c977/32.png) [@Luke\_Scott](https://www.ruby-forum.com/u/Luke_Scott)\
**Post date:** [September 24, 2011, 9:24am UTC](https://www.ruby-forum.com/t/https-variable/212172/2 "2011-09-24T09:24:32Z")

</div>

On 24.09.11 11:12, Luke Scott wrote:

> It would be great if there was an $https variable that was “on” or  
> “off” (or “”) so you could do something like this:  
> fastcgi\_param HTTPS $https;  
> map $scheme $https {  
> https on;  
> default off;  
> }

---

<div class="post-metadata">

**Author:** ![Luke\_Scott](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/d2c977/32.png) [@Luke\_Scott](https://www.ruby-forum.com/u/Luke_Scott)\
**Post date:** [September 24, 2011, 9:26am UTC](https://www.ruby-forum.com/t/https-variable/212172/3 "2011-09-24T09:26:23Z")

</div>

Igor proposed this a while ago:

on the global level (in http{} block)  
map $scheme $php\_https { https on; http off; }

then in fastcgi\_params  
fastcgi\_param HTTPS $php\_https;

---

<div class="post-metadata">

**Author:** ![Luke\_Scott](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/d2c977/32.png) [@Luke\_Scott](https://www.ruby-forum.com/u/Luke_Scott)\
**Post date:** [September 28, 2011, 1:26pm UTC](https://www.ruby-forum.com/t/https-variable/212172/4 "2011-09-28T13:26:14Z")

</div>

Unfortunately, PHP code in many known packages (such as Moodle)  
sometimes relies on the wrong assumption:

$HTTPS = isset($HTTP\_SERVER\_VARS[‘HTTPS’]) ? $HTTP\_SERVER\_VARS[‘HTTPS’]  
: ‘off’;

Because in Apache HTTPS variable is never submitted at all in http mode  
and coders believe this is enough information to check. So, is there a  
way to never submit HTTPS=off at all if HTTPS is not present?

Andrejs

Posted at Nginx Forum:

> **[Re: $https variable?](https://forum.nginx.org/read.php?2,215756,215941#msg-215941)**
>
> It would be great if there was an $https variable that was "on" or "off" (or "") so you could do something like this: fastcgi\_param HTTPS $https; Because currently telling PHP https is enabled is much harder, especially...

---

<div class="post-metadata">

**Author:** ![Luke\_Scott](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/d2c977/32.png) [@Luke\_Scott](https://www.ruby-forum.com/u/Luke_Scott)\
**Post date:** [October 4, 2011, 1:00pm UTC](https://www.ruby-forum.com/t/https-variable/212172/5 "2011-10-04T13:00:27Z")

</div>

On 28 Set 2011 12h25 WEST, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Unfortunately, PHP code in many known packages (such as Moodle)  
> sometimes relies on the wrong assumption:
> 
> $HTTPS = isset($HTTP\_SERVER\_VARS[‘HTTPS’]) ?  
> $HTTP\_SERVER\_VARS[‘HTTPS’] : ‘off’;
> 
> Because in Apache HTTPS variable is never submitted at all in http  
> mode and coders believe this is enough information to check. So, is  
> there a way to never submit HTTPS=off at all if HTTPS is not  
> present?

map $scheme $php\_https {  
default ‘’;  
https on;  
}

fastcgi\_param HTTPS $php\_https;

— appa
