2016-08-16 5 views
0

변수의 이전에 설정된 값을 덮어 쓰려면 어떻게해야합니까? 아래 시나리오에서는 $http_x_forwarded_proto = "https"$redirectToHttps이 false로 설정되지 않고 true로 설정됩니다. 나는이 값을 덮어 쓰길 기대하지만 그렇게하는 것은 아닙니다. 어떻게해야합니까? 의 nginx에서nginx 변수를 덮어 쓰는 법

location/{ 

    set $redirectToHttps false; 
    set $environment "${APP_ENV}"; 

    # determine if we should force https based on the environment 
    if ($environment = "production") { 
     set $redirectToHttps true; 
    } 
    if ($environment = "staging") { 
     set $redirectToHttps true; 
    } 

    # determine if we should force https based on the protocol 
    if ($scheme = "https") { 
     set $redirectToHttps false; 
     return 200 "redirectToHttps-scheme: false"; 
    } 
    if ($http_x_forwarded_proto = "https") { 
     set $redirectToHttps false; 
    } 
+0

'$ http_x_forwarded_proto'가 실제로'https'로 설정되어 있습니까? – VBart

+0

@VBart - 예, 확인했습니다. – Webnet

+0

'$ redirectToHttps'가'true'로 남아 있는지 어떻게 확인합니까? – VBart

답변

1

모든 변수는 단지 문자열, true 또는 false 같은 바이너리 플래그 같은 것은 없다. 따르면

상기 if 지침 documentation :

이 조건은 다음 중 하나 일 수있다 :

  • 변수 이름; 변수의 값이 빈 문자열 또는 "0"이면 false입니다.
  • 은 ...

그렇게 truefalse 동일하게 표현 if ($var) { ... } true로 평가합니다.

관련 문제