简体   繁体   中英

getting 404 error from nginx for a route which is redirecting to a .html file

I have following route in nodejs

app.get('/admin', function (req, res) {
     console.log("CAME HERE");
     res.redirect('/login.html');
});

my nginx.conf looks like this

upstream dev{
    server 127.0.0.1:3001;
}

server {
    listen       80;
    server_name  dev.abc.com;


    location /api {
            proxy_set_header Host $http_host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
            proxy_pass http://dev;
    }

    location /admin {
            proxy_set_header Host $http_host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
            proxy_pass http://dev;
    }

}

Now when I enter this URL in the browser dev.abc.com/admin , the page is getting redirected to http://dev.abc.com/login.html but an error is shown on the browser as follows:

404 Not Found
nginx/1.0.5

things are working fine with localhost.

I think there is something extra to be done from nginx side, not sure what.

Your current Nginx config is only set to serve the node process @port 3001, no mention of any static files.

# replace with your public directory path
root /www/data;

location / {
    try_files $uri $uri/ $uri.html =404;
}

Reference: Serving Static Content

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM