I have an express application that is working perfectly on my local environment on port 3001. I need to deploy it on a production server running nginx listening on port 80. Below are some of the express routes
router.get('/', (req, res) => {
//home page, show login page
});
router.post('/login', (req, res) => {
if(errors){
//invalid credentials
return res.redirect('..');
}
//successful login, redirect to admin area
return res.redirect('../admin');
})
and similar routes for authenticated admin users. The routes are not working properly when deployed on nginx using reverse proxy. The nginx reverse proxy settings are as follows:
location /v2manager/ {
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:3001/;
}
I want the application to be accessible on the route v2manager
on my production domain like example.com/v2manager
. So all the routes become as:
example.com/v2manager/
for the home pageexample.com/v2manager/login
for login POST route, andexample.com/v2manager/admin
for the admin area
However, the redirects are not working properly, on login failure the return res.redirect('..')
redirects me to example.com
which has a different page whereas it should redirect to example.com/v2manager
I can obviously change my application routes to add v2manager
everywhere but the route v2manager
can change frequently depending upon our environments and versioning. Also, a solution that would not hamper the local environment so that localhost:3000/login
would work always