title: How do I make a regex nginx location work?
body: <p>I have the following locations in my nginx config:</p>
  
  <pre><code>server {
      listen       80;
      server_name  localhost;
  
      location ~ ^/(?!api)(.*)/api {
          alias /var/www/api/$1;
      }
  
      location /api {
          alias /var/www/api/latest;
      }
  </code></pre>
  
  <p>I am trying to match /api as the latest version, and /&lt;version&gt;/api as anything else. The non regex location is working fine, but I am getting a 403 on the other location.</p>
  
  <p>I don't think it is anything to do with the file and permissions that are being served, as I get a 403 if I try to access</p>
  
  <pre><code>/latest/api
  </code></pre>
  
  <p>even though these are the same files that are served by</p>
  
  <pre><code>/api
  </code></pre>
  
  <p>Does anyone have an ideas about why I am getting a 403?</p>
  
  <p>The nginx error is: </p>
  
  <pre><code>directory index of "/var/www/api/latest" is forbidden, client:
  172.17.0.1, server: localhost, request: "HEAD /latest/api/ HTTP/1.1",
  host: "localhost"
  </code></pre>