繁体   English   中英

无法将 nginx 代理传递到不同端点上的不同端口

[英]Unable to proxy_pass nginx to different ports on different end points

当在不同的端点上调用时,我试图在不同的端口上反向代理......但由于某种原因,只有根端点'/'似乎有效。 而另一个端点,即位置 /mah/ 似乎不起作用。 下面是default.conf

server {
listen 443 ssl;
server_name    expmple.com;

location / {
    proxy_pass http://localhost:8001/;

}
location /mah/ {
    proxy_pass http://localhost:8000/;
}
 #followed my ssl keys
}

在各个端口上侦听的节点服务器使用 express 为 static 网页提供服务,即


const express = require("express");
const path = require("path");
const app = express();
const PORT =8000;

app.use(express.static(path.join(__dirname, "frontend", "build")));
app.listen(PORT, () => {
  console.log(`Server listening on port ${PORT}`);
});

没有错误,但浏览器中显示空白屏幕。 [注意:当我尝试切换端口时:8000 on / 和 8001 on /mah/. /上一切正常。 但是 /mah/ 不起作用。] 我尝试了多种方法,例如重写,添加 proxy_set_headers 但似乎没有任何效果。 任何帮助表示赞赏。

Nginx 代理应该是 map,在您的快速路由路径中具有相同的路径。

尝试将在端口 8000 上运行的 express 的端点指向/mah 在您的示例中,它应该是这样的。

app.use('/mah', express.static(path.join(__dirname, "frontend", "build")));

为什么它在location /上工作? 因为 Express 应用程序在 8001 端口上运行

app.use(express.static(path.join(__dirname, "frontend", "build")));

默认指向/路由。 这与

app.use('/', express.static(path.join(__dirname, "frontend", "build")));

暂无
暂无

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

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