title: NGINX: Check if Cookies Don't Exist
body: <p>I'm trying to redirect users with NGINX to a different virtual host if they don't have an <code>auth</code> cookie in the request they make. That is, when they visit <code>foo.com</code>, if an <code>auth</code> cookie is present, then they should see <code>foo.com</code>; if they lack an <code>auth</code> cookie, they should see <code>signup.foo.com</code>. </p>
  
  <p>I've read through "If is Evil" from NGINX, and I was able to successfully check whether users had cookies. I did that by doing:</p>
  
  <pre><code>if ($cookie_auth) {
       redirect 301 https://signup.foo.com;
  }
  ...
  </code></pre>
  
  <p>But, of course, that's doing the <em>opposite</em> of what I want to happen. I also tried doing a map, like the following:</p>
  
  <pre><code>map $cookie_auth $no_auth {
      default 0;
      '' 1;
  }
  
  server {
       ...
       if ($no_auth) { return 301 https://signup.foo.com; }
       ...
  }
  </code></pre>
  
  <p>But that seemed to redirect everything to signup.foo.com. Pretty much the essence of my question is how to use a <code>NOT</code> operator in NGINX. Something like <code>if (!$cookie_auth)</code>, for example.</p>