title: Nginx how to match a dynamic location
body: <p>I have a nginx config file with a server context and multiple location contexts. How can I get the <code>/</code> in one of the location contexts to match a route that is dynamically generated? It's dynamically generated because my application connects to an api which returns <code>/number?somelongquerystring</code> which I concat with my existing route using javascript. This isn't a real directory, its simply used for <a href="https://reacttraining.com/react-router/" rel="nofollow noreferrer">React Router</a> to display different data from the api using <a href="https://reactjs.org/" rel="nofollow noreferrer">React</a>.</p>
  
  <p>When I hard code the route it works fine.</p>
  
  <pre><code>server {
          listen 80;
          server_name localhost2;
  
          # more location contexts ...
  
          location /user/1231375741 { # My route
              proxy_pass http://litphum;
          }
      }
  </code></pre>
  
  <p>Would show something like
  <code>http://localhost2/user/1231375741?access_token=BQDY6N-6RKgsE-c0Op8Q_neX02q_dnVixn_biBKJg_JOZH5C</code></p>
  
  <p>The <code>/1231375741</code> in this implementation is whats dynamically generated as well as the query string after it that is displayed in the url. The route will always begin with <code>/user</code> so I tried using RegEx to make this work with the help of <a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#location" rel="nofollow noreferrer">nginx's docs</a></p>
  
  <pre><code>server {
          listen 80;
          server_name localhost2;
  
          # more location contexts ...
  
          location ~* ^/user/[a-zA-z\d]* {
              proxy_pass http://litphum;
          }
      }
  </code></pre>
  
  <p>I've tried the <code>.*</code> regex too but no luck. If the whole config file would help here it is.</p>
  
  <pre><code>worker_processes 1;
  
  events { worker_connections 1024; }
  
  http {
      server {
          listen 80;
          server_name localhost2;
          location / {
              proxy_pass http://litphum;
          }
          location /login {
              proxy_pass http://litphum-backend:8888/login;
          }
          location /callback {
              proxy_pass http://litphum-backend:8888/callback;
          }
          location ~* ^/user/[a-zA-z\d]* {
              proxy_pass http://litphum;
          }
      }
  }
  </code></pre>