在我的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/route或http://myserver.com/node/1210时,出现错误Cannot GET //route
。
任何想法如何我可以更新我的Apache配置,以保持Express路线?
我在CentOS上运行Apache 2.4.6。
这只是一个提示:它使用nginx代理节点,没有考虑过使用nginx到apache inves? –
谢谢!但不幸的是使用nginx不是一个选项。 – stekhn