Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
101
Help us understand the problem. What is going on with this article?
@ukitazume

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

More than 5 years have passed since last update.

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

101
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ukitazume
Yahoo!Japan/Pankaku/Engine Yard Ruby/Infrastructure/Angularjs/English/Golang/CoreOS/Deis/Kubernetes

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
101
Help us understand the problem. What is going on with this article?