Nginx - how to enable ssl for PHP when behind a reverse proxy
You may solve this in two ways... at the application level or at the Nginx level.
At the application level
Since, it is a PHP application, you may use the following at the top of the code / application...
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') $_SERVER['HTTPS']='on';
At the Nginx level
Step 1: Map X-Forwarded-Proto to a variable whose value depends on X-Forwarded-Proto.
map $http_x_forwarded_proto $fastcgi_param_https_variable {
default '';
https 'on';
}
Step 2: Replace the existing line fastcgi_param HTTPS $https $if_not_empty
with the following line that sets fastcgi_param HTTPS based on the above variable
fastcgi_param HTTPS $fastcgi_param_https_variable;
Personally, I prefer the first method since it requires just a single line to set things correctly. The second method should work too, but is not tested.