set _SERVER["HTTPS"] to yes with stunnel Haproxy Nginx

Sairam asked:

I am trying to set the _SERVER[“HTTPS”] php variable to yes on my web servers.

Actually, https trafic come to stunnel which forward it to haproxy which forward it to my web servers running under nginx.

Trying to add this in haproxy.cfg:

    reqidel ^HTTPS:
    reqadd HTTPS:\ yes

But instead of clear HTTPS and add HTTPS to yes it adds a new variable:


Any idea?


My answer:

I suspect you really need X-Forwarded-Proto instead. This header is a convention by which the reverse proxy can tell the origin server that a connection was HTTPS, even if the connection between reverse proxy and origin server is not. Most common web applications already check for this header, and you can easily check for it in a custom web app.

reqadd X-Forwarded-Proto:\ https if { ssl_fc }

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.