I'm running a Koa app on port 5000, and i'd like Ngnix to serve the app in a sub-directory - e.g: http://example.com/myNodeApp
Here's what I've currently got in /etc/nginx/sites-enabled/default
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/;
}
This kind of works... apart from the fact that any redirect e.g this.redirect('/')
in my Koa app goes to the the nginx web root /
Also, it doesn't render anything from my Koa apps' public
directory e.g. stylesheets, javascript and images.
What am I doing wrong? Thanks.
location /myNodeApp/ {
– Fulklocation /myNodeApp/ { ... }
(without the regular expression as you suggested), gives the same result. – ReisingerLocation
header? With domain part. BecauseLocation
header rewriting work only if your node application redirect to localhost:5000. But if node application redirects to localhost - custom rewrite required. So, need to know how location header looks like. – Fulkserver { ... }
block. This is all a bit new to me! – Reisingercurl -I http://localhost:5000 HTTP/1.1 200 OK Content-Type: text/html; charset=utf-8 Content-Length: 2730 Date: Tue, 11 Oct 2016 20:49:53 GMT Connection: keep-alive
– Reisingercurl
node's URL which executethis.redirect('/')
– FulkLocation: http://xxxxx/xxx
. Depend on domain part - nginx can rewrite it or not. If this domain partlocalhost:5000
- nginx can rewrite this redirect as default behavior. If node application using another domain part (http://localhost/xxxx
for example) - you need to add customproxy_redirect
directive. – Fulk