title: How to look for a certain header in nginx
body: <p>I'm using nginx as a proxy server to basically serve image files and hand off everything else to another server at port 9000.</p>
  
  <p>What I want to do is have nginx return an HTTP 500 error code if the incoming request does not contain a specific header (X-AUTH-TOKEN), but only if the requests are not for the resources "/register" or "/events". In that case, they need to go straight to port 9000.</p>
  
  <p>Here's the configuration I currently have:</p>
  
  <pre><code>http {
  
      sendfile on;
  
      upstream my-backend {
          server 127.0.0.1:9000;
      }
  
      # main ngingx server
      server {
          server_name localhost;
  
          location / {
              proxy_pass http://my-backend;
          }
  
          location /images/ {
              root /home/images;
          }
      }
  }
  </code></pre>
  
  <p>Any idea how to implement this kind of logic? Thanks.</p>