# Passing header information on to backend Apache/PHP

**URL:** <https://www.ruby-forum.com/t/passing-header-information-on-to-backend-apache-php/164766>\
**Category:** NGINX\
**Created:** [April 5, 2009, 3:13pm UTC](https://www.ruby-forum.com/t/passing-header-information-on-to-backend-apache-php/164766 "2009-04-05T15:13:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_Langhans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/54ee81/32.png) [@Peter\_Langhans](https://www.ruby-forum.com/u/Peter_Langhans)\
**Post date:** [April 5, 2009, 3:13pm UTC](https://www.ruby-forum.com/t/passing-header-information-on-to-backend-apache-php/164766/1 "2009-04-05T15:13:00Z")

</div>

Hi,

I’m using nginx 0.6.35, apache 2.0.63 and php 5.2.9.

My problem is, that I need my php scripts to know in some way or another  
whether SSL is used or not (to include either https or http javascript  
files  
e.g.).

When using nginx as webfrontend proxy, it accepts all the ssl  
connections  
and it’s working fine, but when I proxy through to apache, the knowledge  
about SSL is ‘lost’. If possible, I don’t want to be using different  
ports  
for proxying through to apache.

I thought it’d be enough to set headers like:

for 80:  
proxy\_set\_header X-Secure of;

for 443:  
proxy\_set\_header X-Secure on;

put I have not found a way how I could retrieve those values from within  
the  
php script. They seem to be filtered out by Apache.

Does anyone have an idea how I can get any custom set header, set in the  
nginx.conf through to the php scripts?

Thanks a lot,  
Peter

---

<div class="post-metadata">

**Author:** ![Peter\_Langhans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/54ee81/32.png) [@Peter\_Langhans](https://www.ruby-forum.com/u/Peter_Langhans)\
**Post date:** [April 5, 2009, 3:44pm UTC](https://www.ruby-forum.com/t/passing-header-information-on-to-backend-apache-php/164766/2 "2009-04-05T15:44:38Z")

</div>

How about a rewrite rule that passes a parameter to your PHP script:

* * *

From: removed\_email\_address@domain.invalid [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of  
Peter  
Langhans  
Sent: Sunday, April 05, 2009 8:03 AM  
To: removed\_email\_address@domain.invalid  
Subject: passing header information on to backend Apache/PHP

Hi,

I’m using nginx 0.6.35, apache 2.0.63 and php 5.2.9.

My problem is, that I need my php scripts to know in some way or another  
whether  
SSL is used or not (to include either https or http javascript files  
e.g.).

When using nginx as webfrontend proxy, it accepts all the ssl  
connections and  
it’s working fine, but when I proxy through to apache, the knowledge  
about SSL  
is ‘lost’. If possible, I don’t want to be using different ports for  
proxying  
through to apache.

I thought it’d be enough to set headers like:

for 80:  
proxy\_set\_header X-Secure of;

for 443:  
proxy\_set\_header X-Secure on;

put I have not found a way how I could retrieve those values from within  
the php  
script. They seem to be filtered out by Apache.

Does anyone have an idea how I can get any custom set header, set in the  
nginx.conf through to the php scripts?

Thanks a lot,  
Peter

---

<div class="post-metadata">

**Author:** ![Peter\_Langhans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/54ee81/32.png) [@Peter\_Langhans](https://www.ruby-forum.com/u/Peter_Langhans)\
**Post date:** [April 5, 2009, 3:45pm UTC](https://www.ruby-forum.com/t/passing-header-information-on-to-backend-apache-php/164766/3 "2009-04-05T15:45:48Z")

</div>

What about passing parameter to your PHP script using rewrite rule?

rewrite ^(.\*)$ http:// \<http:///\>  
/login.php?proto=SSL

I might not be understanding your exact problem though.

-Larry B.

* * *

From: removed\_email\_address@domain.invalid [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of  
Peter  
Langhans  
Sent: Sunday, April 05, 2009 8:03 AM  
To: removed\_email\_address@domain.invalid  
Subject: passing header information on to backend Apache/PHP

Hi,

I’m using nginx 0.6.35, apache 2.0.63 and php 5.2.9.

My problem is, that I need my php scripts to know in some way or another  
whether  
SSL is used or not (to include either https or http javascript files  
e.g.).

When using nginx as webfrontend proxy, it accepts all the ssl  
connections and  
it’s working fine, but when I proxy through to apache, the knowledge  
about SSL  
is ‘lost’. If possible, I don’t want to be using different ports for  
proxying  
through to apache.

I thought it’d be enough to set headers like:

for 80:  
proxy\_set\_header X-Secure of;

for 443:  
proxy\_set\_header X-Secure on;

put I have not found a way how I could retrieve those values from within  
the php  
script. They seem to be filtered out by Apache.

Does anyone have an idea how I can get any custom set header, set in the  
nginx.conf through to the php scripts?

Thanks a lot,  
Peter

---

<div class="post-metadata">

**Author:** ![Peter\_Langhans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/54ee81/32.png) [@Peter\_Langhans](https://www.ruby-forum.com/u/Peter_Langhans)\
**Post date:** [April 5, 2009, 4:05pm UTC](https://www.ruby-forum.com/t/passing-header-information-on-to-backend-apache-php/164766/4 "2009-04-05T16:05:06Z")

</div>

Hi Larry,

thx for that. I considered that as well, but I find the solution  
somewhat  
“unelegant”. It should either be identified by the port (which is hard  
due  
to architecture setup in my case) or a header (which I would prefer).

Thx for hinting this solution out again. Maybe I really should consider  
it  
and put my desire for ‘compliable’/‘elegant’ solutions into the bin…  
☹  
(which would hurt my heart).

Bests,  
Pete

---

<div class="post-metadata">

**Author:** ![Peter\_Langhans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/54ee81/32.png) [@Peter\_Langhans](https://www.ruby-forum.com/u/Peter_Langhans)\
**Post date:** [April 5, 2009, 4:39pm UTC](https://www.ruby-forum.com/t/passing-header-information-on-to-backend-apache-php/164766/5 "2009-04-05T16:39:41Z")

</div>

On Apr 05, Peter Langhans wrote:

> about SSL is ‘lost’. If possible, I don’t want to be using different ports  
> put I have not found a way how I could retrieve those values from within the  
> php script. They seem to be filtered out by Apache.
> 
> Does anyone have an idea how I can get any custom set header, set in the  
> nginx.conf through to the php scripts?

Please show us your config and php script.

---

<div class="post-metadata">

**Author:** ![Peter\_Langhans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/54ee81/32.png) [@Peter\_Langhans](https://www.ruby-forum.com/u/Peter_Langhans)\
**Post date:** [April 5, 2009, 4:35pm UTC](https://www.ruby-forum.com/t/passing-header-information-on-to-backend-apache-php/164766/6 "2009-04-05T16:35:00Z")

</div>

Larry,

thanks for your reply again. Sorry I stole your time for my own  
dumbness.

It’s totally possible to do it via headers. The example I gave above,  
works  
perfectly. I have just been too dump to test it in https (I tested in  
http)  
and wondered why the header does not come through as expected ☹ Oh  
lord.

So just for reference. As the manual states correctly, you can pass any  
header information on to your backend scripts via the

proxy\_set\_header Header-Name Header-Vale;

directive. Apache does NOT filter it out, and it’s visible within PHP by  
using one of the two following options:

1.) use the normal $\_SESSION variable. CAVEAT: when using the $\_SESSION  
variable your header “Header-Name” becomes “HTTP\_HEADER\_NAME” (watch  
casing  
and underscore instead of dash)

2.) use the apache\_request\_headers function to retrieve  
original/unchanged  
values ([PHP: apache\_request\_headers - Manual](http://uk.php.net/apache_request_headers))

Thanks for your time, folks!

Pete

---

<div class="post-metadata">

**Author:** ![Peter\_Langhans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/54ee81/32.png) [@Peter\_Langhans](https://www.ruby-forum.com/u/Peter_Langhans)\
**Post date:** [April 5, 2009, 6:06pm UTC](https://www.ruby-forum.com/t/passing-header-information-on-to-backend-apache-php/164766/7 "2009-04-05T18:06:56Z")

</div>

Hi Gena,

thx for the reply. Works perfectly as well!

Bests,  
Pete

---

<div class="post-metadata">

**Author:** ![Peter\_Langhans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/54ee81/32.png) [@Peter\_Langhans](https://www.ruby-forum.com/u/Peter_Langhans)\
**Post date:** [April 5, 2009, 5:38pm UTC](https://www.ruby-forum.com/t/passing-header-information-on-to-backend-apache-php/164766/8 "2009-04-05T17:38:49Z")

</div>

On Sunday, April 5, 2009 at 16:02:34, Peter Langhans wrote:

PL\> My problem is, that I need my php scripts to know  
PL\> in some way or another whether SSL is used or not  
PL\> (to include either https or http javascript files e.g.).

PL\> When using nginx as webfrontend proxy, it accepts all the ssl  
PL\> connections and it’s working fine, but when I proxy through to  
PL\> apache, the knowledge about SSL is ‘lost’. If possible, I don’t  
PL\> want to be using different ports for proxying through to apache.  
…  
PL\> Does anyone have an idea how I can get any custom set header,  
PL\> set in the nginx.conf through to the php scripts?

# nginx config:

proxy\_set\_header X-Nginx-Scheme $scheme;

# nginx variable $scheme will be ‘http’ or ‘https’.

# apache config:

SetEnvIf X-Nginx-Scheme “^https$” HTTPS=on

# Apache environment variable HTTPS will be ‘on’ or not defined.

# PHP code:

$scheme = getenv(‘HTTPS’) && strtolower(getenv(‘HTTPS’)) != ‘off’  
? ‘https’  
: ‘http’;

# PHP variable $scheme will be ‘http’ or ‘https’.
