title: Serve express dynamic URL using NGINX with Nodejs reverse proxy
body: <p>I am using Express for serving static files and dynamic URLs on my nodejs app. I am generating a URL based on the :id in Mongodb and then on NGINX I am using Nodejs reverse proxy to serve this path to the user but it doesn't work whatever I try. It always says "CANNOT GET.."</p>
  
  <p>I am running NGINX 1.14.2, Node 8.14.0. I have tried NGINX rewrite directive and various wild cards ( ~<em>, ~^, .</em>, etc.) but none of them have worked. I have included the current express code and NGINX config below. Any help is hugely appreciated</p>
  
  <p>Express</p>
  
  <pre><code>    router.get('/dynamic-uri/:fooId', function (req, res) {
           res.render('index');
      });
  </code></pre>
  
  <p>The resultant URL with :fooId is</p>
  
  <pre><code>   https://example.com/myNodeApp/dynamic-uri/5c35e51228122504b57126d7
  </code></pre>
  
  <p>NGINX Config</p>
  
  <pre><code>location /myNodeApp/dynamic-uri {
      proxy_pass http://x.x.x.x:3000;
      proxy_http_version 1.1;
      proxy_redirect off;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection 'upgrade';
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $host;
      proxy_set_header X-NginX-Proxy true;
      proxy_cache_bypass $http_upgrade;
      proxy_set_header X-Real-IP $remote_addr;
  }
  </code></pre>
  
  <p>Of course the :fooId doesn't exist as a static path and to serve static files i have the following block which works fine</p>
  
  <pre><code>location ~* /myNodeApp/(static|img|media|app|css|js) {
      proxy_pass http://x.x.x.x:3000;
      proxy_http_version 1.1;
      proxy_redirect off;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-NginX-Proxy true;
      proxy_cache_bypass $http_upgrade;
      proxy_set_header X-Real-IP $remote_addr;
  }
  </code></pre>