简体   繁体   English

对于重定向到 .html 文件的路由,从 nginx 获取 404 错误

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

I have following route in nodejs我在 nodejs 中有以下路线

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

my nginx.conf looks like this我的 nginx.conf 看起来像这样

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:现在,当我在浏览器dev.abc.com/admin输入这个 URL 时,页面被重定向到http://dev.abc.com/login.html但浏览器上显示如下错误:

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.我认为从 nginx 方面还有一些额外的事情要做,不确定是什么。

Your current Nginx config is only set to serve the node process @port 3001, no mention of any static files.您当前的 Nginx 配置仅设置为为节点进程 @port 3001 提供服务,没有提及任何静态文件。

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

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

Reference: Serving Static Content参考: 提供静态内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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