LoginSignup
120
104

More than 5 years have passed since last update.

Nginxで複数条件のIF文を書く方法がすごいw

Last updated at Posted at 2014-04-02

NginxでIf文を if ($host = 'www.example.com' && $request_uri ~ "/admin") という風には書けない。
入れ子にもできません。(ディレクティブなので?)

そこで逃げ道は 文字列結合で判定

    if ($request_uri = /) { 
      set $test  A; 
    } 

    if ($host ~* teambox.com) { 
      set $test  "${test}B"; 
    } 

    if ($http_cookie !~* "auth_token") { 
      set $test  "${test}C"; 
    } 

    if ($test = ABC) { 
      proxy_pass http://teambox-cms.heroku.com; 
      break; 
    } 

参考(というかそのものですが)
https://gist.github.com/jrom/1760790

ちなみにifisevilと公式ドキュメントにあります。使わないほうが良さそう。
http://wiki.nginx.org/IfIsEvil

120
104
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
120
104