title: How to check if authorization header exists in Nginx?
body: <p>I am trying to catch requests without authorization header in Nginx and redirect it to a different path.</p>
  
  <pre><code>server {
      ...
  
      location @authorized {
  
              if($http_authorization){
                  // Do stuff
              }
      }
  }
  </code></pre>
  
  <p>This is what I get when I run nginx -t</p>
  
  <blockquote>
    <p>nginx: [emerg] unknown directive "if($http_authorization)"</p>
  </blockquote>
  
  <p>The header seems to be in place as when I try to debug using this in the place of the above if I get the header back.</p>
  
  <pre><code>add_header 'X-myheader' '$http_authorization' always;
  return 418;
  </code></pre>