title: Node JS - Nginx - proxy_pass to a subdirectory - Koa
body: <p>I'm running a Koa app on port 5000, and i'd like Ngnix to serve the app in a sub-directory - e.g: <code>http://example.com/myNodeApp</code></p>
  
  <p>Here's what I've currently got in <code>/etc/nginx/sites-enabled/default</code></p>
  
  <pre><code>        location ^~ /myNodeApp/ {
              proxy_set_header X-Real-IP $remote_addr;
              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_pass    http://localhost:5000/;
          }
  </code></pre>
  
  <p>This <em>kind of</em> works... apart from the fact that any redirect e.g <code>this.redirect('/')</code> in my Koa app goes to the the nginx web root <code>/</code></p>
  
  <p>Also, it doesn't render anything from my Koa apps' <code>public</code> directory e.g. stylesheets, javascript and images.</p>
  
  <p>What am I doing wrong? Thanks.</p>