Tuesday, 4 April 2017

NGINX + Node.js res.redirect('../Path')

I have node app that does the following

app.get('/', function (req, res) {
    res.redirect('../Path');
});

app.get('/Path, function(req, res){
    res.render('page');
});

going to <servername>:<port>/ redirects to <servername>:<port>/Path and page loads

This works fine. Now I'm adding NGINX to the equation and I want all my node path under the location Location1 so I have this in NGINX:

location /Location1/ {
    proxy_pass http://localhost:port/
    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;
}

That works fine if I go directly to <servername>/Location1/Path but does not work if I try to go to <servername>/Location1 it redirects to <servername>/Path1

I thought the ../Path in the redirect is for relative urls but apparently it does not work in this case. What am I doing wrong?



via Woodsy

No comments:

Post a Comment