就是这种情况。我有一个运行在我主要域名上的Wordpress网站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
但没有一条可行。以下是我的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/$1 [P,L]
ProxyPassReverse /node/ http://127.0.0.1:3000/
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句