title: Nginx location statement behaves differently in regex and normal matching
body: <p>I'm seeing different behaviour in these two cases:</p>
  
  <pre><code>location ~ /(?&lt;version&gt;v[12]) {
      proxy_pass https://localhost/api/$version;
  }
  
  location /v2 {
      proxy_pass https://localhost/api/v2;
  }
  </code></pre>
  
  <p>If I request <code>/v2/login</code>, I see a request to <code>/v2</code> in the regex configuration, whereas the direct match correctly retains the entire request url.</p>
  
  <p>I tried adding a second capture group, <code>/(?&lt;version&gt;v[12])/(?&lt;path&gt;.*)</code>, and then it works, mostly. However, it seems to mess with PUT/POST. </p>
  
  <p>Is there some explanation I'm missing? I read the <a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#location" rel="nofollow">documentation</a>, but as far as I can tell there isn't supposed to be any difference between the use of regex or not using it.</p>