如何将api节点与nginx位置进行映射



我正在尝试在nginx上运行节点应用程序。

这是我的nginx配置。

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

这是节点应用程序路由器。

app.use('/', indexRouter);
app.use('/api', apiRouter);

但当我通过x.x.x/first访问服务器时,我会得到404个错误。原因是什么。如果你知道,请告诉我。

这可能是因为您在NGINX侧的位置配置。

所以根据我想你想做的:

/first/ -> Node Index Route
/first/api -> Node API Route

这将导致以下配置

server {
....

location /first {
rewrite ^/first(.*)$ /$1 break;
proxy_pass http://localhost:3000
....
}
}

最新更新