Node.js 和 Wordpress 的 Apache 代理在相同 "Domain" 但路径不同

Apache Proxy for Node.js and Wordpress on same "Domain" but different paths

情况是这样的。 我的主域上有一个 Wordpress 网站 运行ning http://www.example.com.

.htaccess 在服务器上启用,我正在使用 Wordpress 永久链接生成漂亮的 URL。

现在我在 Node.js (Express) 中有另一个应用程序,我已将其部署在同一台服务器上,并且正在 运行 宁在端口号 3000 上。因此,如果我输入 http://www.example.com:3000 它会触发我的 Expressjs 应用程序。 运行宁完美无缺。

我想要的是 运行 来自同一域的特定路径上的 Node.js 应用程序。例如,如果我点击 http://www.example.com/node,它应该将用户带到我的 Node.js 应用程序,如果我使用 Apache mod_proxy,它会很好地运行。但这仅适用于我的 Expressjs 路由器的 / 路由。 但我还有其他几条路线,例如/subscribe/confirm 但其中 none 有效。 以下是我的 Apache 配置,我试图通过提供多个 ProxyPass 指令来使其工作,但它不起作用。

ProxyPass /node http://127.0.0.1:3000/
ProxyPassReverse /node http://127.0.0.1:3000/
ProxyPass /node/subscribe http://127.0.0.1:3000/subscribe
ProxyPassReverse /node/subscribe http://127.0.0.1:3000/subscribe

Express 路由器非常基础,使用以下应用配置:

var router  = express.Router();
app.use("/",router);

router.get("/",function(req,res){
   res.sendFile(templatepath + "index.html");
});

router.get("/subscribe",function(req,res){
   res.sendFile(templatepath + "subscribe.html");
});

router.get("*",function(req,res){
   res.sendFile(templatepath + "404.html");
});

当我尝试加载 http://www.example.com/node/subscribe 时,它只是加载 * 路由并显示 404.html 模板。

终于通过如下修改Apache配置文件使其工作:

ProxyPreserveHost On
RewriteEngine On
ProxyPass ^/node/(.*) http://127.0.0.1:3000/ [P,L]
ProxyPassReverse /node/ http://127.0.0.1:3000/