title: Reserve proxy to different locations based on URL subpath
body: <p>I have different services that will handle different parts of the URL depending on the params being passed</p>
  
  <p>Service <code>offer</code> will handle the route <code>/offer/44</code> and other routes like <code>/offer/44/calculator</code> the following code successfully handles that. </p>
  
  <pre><code> location ^~ /offer {
              location ^~ /offer {
                  rewrite ^/offer/(.*)$ /offer/$1 break;
                  proxy_pass http://localhost:4000/;
              }
          } 
  </code></pre>
  
  <p>But my extra layer of complexity comes when I have the url <code>/offer/44/payments/*</code> and that then should be routed through another service</p>
  
  <p>I tried lots of different variants of nesting locations but nothings seems to work for <code>payments</code>. Tried to do something like the following (the redirect is basic right now as i was just trying to make it just redirect... but ideally i want it to take everything after <code>payment</code> and put it into the other service URL)</p>
  
  <pre><code>    location ^~ /offer {
              location ^~ /offer {
                  rewrite ^/offer/(.*)$ /offer/$1 break;
                  proxy_pass http://localhost:4000/;
              }
  
              #my ideal /offer/44/payments/*
              location ^/offer/([0-9]+)/payment/(.*)$ {
  
                  proxy_pass http://payment-docker.local:20000/init;
              } 
          } 
  </code></pre>
  
  <p>So my question is: How do I make local nesting work so that if it sees the word <code>payments</code> after <code>offer</code> it proxy_pass to another service?</p>
  
  <p><strong>UPDATED:</strong> </p>
  
  <p>to make it even more simplistic </p>
  
  <p>Some of the things i've tried</p>
  
  <p>It seems that what <code>nginx</code> doesnt like is the numbers</p>
  
  <p><strong>This works</strong></p>
  
  <pre><code># Example URL = http://localhost/offer/
   location ^~ /offer/ {
                  proxy_pass http://payment-docker.local:20000/init;
           }
  </code></pre>
  
  <p><strong>This doesn't work</strong>. as soon as there is a number regex it always returns <code>404</code></p>
  
  <pre><code># Example URL = http://localhost/offer/3
       location ^~ /offer/([0-9]+) {
                      proxy_pass http://payment-docker.local:20000/init;
               }
  # Example URL = http://localhost/offer/33
       location ^~ "/offer/[\d]{2}" {
                      proxy_pass http://payment-docker.local:20000/init;
               }
  </code></pre>