Nginx – HTTPS variable in $_SERVER using nginx as reverse proxy

apache-2.2drupalhttpsnginxreverse-proxy

I'm using nginx as a reverse proxy in front of an apache with mod_php. My site is on https, and it would require the variable $_SERVER['HTTPS'] to be set 'on' to assemble some of the links correctly. My site is on drupal, so it is not an option to fix the code and check an other variable when deciding if the site runs under https.

Is there a way to fix the issue only with tweaking the nginx or apache configuration?

I found other people asking similar questions, but I did not found a solution that suits me, neither a clear statement that what I want is not possible.

(e.g.: HTTPS server/php variable not available,
Nginx : strip header on HTTP, add header on HTTPS)

Best Answer

You can use a directive SetEnv HTTPS "on" in Apache main configuration or in .htaccess to set the required variable to on unconditionally.

Or better - set it only if client address equals the address of Nginx frontend. In this case the variable won't be set if clients request Apache directly without SSL:

SetEnvIf Remote_Addr "NGINX_IP_ADDRESS" HTTPS=on
Related Topic