title: Nginx allow only root and api locations
body: <p>I have a server configured as a reverse proxy to my server. I want to reject all the requests except to two locations, one for root and another the api root.</p>
  
  <p>so the server should only allow requests to the given paths</p>
  
  <pre><code>example.com/ (only the root)
  example.com/api/ (every url after the api root)
  </code></pre>
  
  <p>The expected behaviour is that the server should reject all the below possibilities.</p>
  
  <pre><code>example.com/location
  example.com/location/sublocation
  example.com/dynamic-location
  </code></pre>
  
  <p>my current nginx configuration,</p>
  
  <pre><code>server {
  
     # server configurations
  
     location / {
  
          # reverse proxy configurations
  
      }
  
  }
  </code></pre>
  
  <p>How do I set up this configuration?</p>