I'm trying to run some nodejs app on a server (Ubuntu 14.04), using Nginx and i'm almost done. Here's my server configuration (/etc/nginx/sites-available/default
):
server {
listen 80;
server_name my_domain.com;
location /test1 {
proxy_pass http://127.0.0.1:5000/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /test2 {
proxy_pass http://127.0.0.1:5001/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
I've got several apps running, and they all works well, i can acces them with http://my_domain.com/test1
, http://my_domain.com/test2
, etc...
The problem is that inside one of this apps i've got several absolute paths:
e.g. <a href="/">Home</a>
or (inside express)
res.redirect('/');
This redirects don't go to http://my_domain.com/test1
but they go to http://my_domain.com/
Is there a way, through nginx configurations, to tell the app that the root location is actually http://my_domain.com/test1
?
I'm really new to nginx and to virtual hosts in general, i'm trying to learn... Any help would be appreciated.
EDIT:
The result of curl -I http://127.0.0.1:5000
is:
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: text/html; charset=utf-8
Content-Length: 1376
ETag: W/"560-GGm/YYltkhKxiOVNZ99jqQ"
set-cookie: connect.sid=s%3AkZYCqLKvbhHhK3W8ECBN8G91s41paws4.ekLWefrd3NdQatT3VzFNozfnFs65YBEW9k9MNTdbQT0; Path=/; HttpOnly
Date: Sat, 15 Aug 2015 13:13:20 GMT
Connection: keep-alive
As you can see i don't get a Location Header...
By the way, i managed to solve the problem using subdomains, that seem to work as i expected... Anyway an answer would be appreciated, since i might need it in the future.