对于重定向到 .html 文件的路由,从 nginx 获取 404 错误
getting 404 error from nginx for a route which is redirecting to a .html file
我在 nodejs 中有以下路线
app.get('/admin', function (req, res) {
console.log("CAME HERE");
res.redirect('/login.html');
});
我的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;
}
}
现在,当我在浏览器 dev.abc.com/admin
中输入此 URL 时,页面被重定向到 http://dev.abc.com/login.html
但浏览器上显示如下错误:
404 Not Found
nginx/1.0.5
本地主机运行良好。
我认为 nginx 方面还有一些额外的事情要做,不确定是什么。
您当前的 Nginx 配置仅设置为服务节点进程@port 3001,没有提及任何静态文件。
# replace with your public directory path
root /www/data;
location / {
try_files $uri $uri/ $uri.html =404;
}
我在 nodejs 中有以下路线
app.get('/admin', function (req, res) {
console.log("CAME HERE");
res.redirect('/login.html');
});
我的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;
}
}
现在,当我在浏览器 dev.abc.com/admin
中输入此 URL 时,页面被重定向到 http://dev.abc.com/login.html
但浏览器上显示如下错误:
404 Not Found
nginx/1.0.5
本地主机运行良好。
我认为 nginx 方面还有一些额外的事情要做,不确定是什么。
您当前的 Nginx 配置仅设置为服务节点进程@port 3001,没有提及任何静态文件。
# replace with your public directory path
root /www/data;
location / {
try_files $uri $uri/ $uri.html =404;
}