2016-08-16 14 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に評価されます。

関連する問題