title: nginx reject request if header not present
body: <p>I need nginx to reject requests if header <code>StaticCookie</code> is not present. I don't care about its value, I just need for it to exist.</p>
  
  <p>What I came up with is this, but this doesn't work. Nginx allows requests with no headers at all.</p>
  
  <pre><code>    if ($http_StaticCookie = false) {
        return 403;
      }
  
  
  
      root /usr/share/asuno/www;
  
      location ~* /css/ {
          expires max;
      }
  
      location ~* /js/ {
          expires max;
      }
  </code></pre>
  
  <p>I saw this post -
  <a href="https://stackoverflow.com/questions/18970620/nginx-reject-request-if-header-is-not-present-or-wrong">Nginx: Reject request if header is not present or wrong</a> - but it deals with defined header values. What I need is to check mere existence of the header.</p>
  
  <p>I tried putting <code>location</code> directives inside the <code>if</code> clause but then nginx throws errors trying to read the config.</p>
  
  <p>How can this be done?</p>