2015-10-15 60 views
5

在我的Apache config im中,将/node上的所有流量转发到Express服务器正在侦听的端口3000如何设置Apache ProxyPass以保留Express路由

<IfModule mod_proxy.c> 

    ProxyRequests Off 

    ProxyPass /node http://localhost:3000/ 

</IfModule> 

的快速应用程序是这样的:

var express = require('express'); 

var app = express(); 
var router = express.Router(); 

router.route('/route/:id').get(function (req, res) { 

    res.json({ description: 'Welcome to a route with an ID' }); 
}); 

router.route('/route').get(function (req, res) { 

     res.json({ description: 'Welcome to the normal route' }); 
}); 

router.route('/').get(function (req, res) { 

    res.json({ data: 'Welcome to the app' }); 
}); 

app.use('/', router); 

app.listen(3000); 

当我指挥我的浏览器http://myserver.com/node我得到的回应{ data: 'Welcome to the app' },这是罚款。虽然,当我尝试去http://myserver.com/node/routehttp://myserver.com/node/1210时,出现错误Cannot GET //route

任何想法如何我可以更新我的Apache配置,以保持Express路线?

我在CentOS上运行Apache 2.4.6。

+0

这只是一个提示:它使用nginx代理节点,没有考虑过使用nginx到apache inves? –

+0

谢谢!但不幸的是使用nginx不是一个选项。 – stekhn

回答

8

您的主机末端还有一个/。尝试更改为:

ProxyPass /node http://localhost:3000 
+0

非常感谢。那就是诀窍。现在我将自己去脸上。 – stekhn