I am trying to add following block in http context to set $https based on $http_x_forwarded_proto:

map $http_x_forwarded_proto $https {
    default off;
    https on;

But configuration test fails saying:

nginx: [emerg] the duplicate "https" variable in /etc/nginx/nginx.conf:36
nginx: configuration file /etc/nginx/nginx.conf test failed
  • Going to ask the obvious... did you declare the variable https already? – Grumpy Jan 3 '13 at 0:03
  • No. Where and how should I set it. I tried set $https off; but its not allowed here. – Naveed Jan 3 '13 at 0:07
  • Post rest of your config. On a side note, I find the naming of a variable "https" quite poor choice, since there's one very close ($http) in nginx that's reserved. – Grumpy Jan 3 '13 at 2:38

There is from a change in versin 1.1.11, where the variable $https became an internal variable.

Since it's now an internal, and the request itself isn't over HTTP, the best way is to pass along this info to the fastcgi handler. Here is what I have in my nginx.conf (via an include)

map $http_x_forwarded_proto $fastcgi_https {
  default '';
  https on;

Then I have the below in the location block handling the fastcgi_pass

fastcgi_param HTTPS $fastcgi_https;
fastcgi_param SERVER_PORT $http_x_forwarded_port;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.