【发布时间】:2016-01-14 03:41:53
【问题描述】:
在我的 Apache 配置中,我将 /node 上的所有流量转发到 Express 服务器正在侦听的端口 3000。
<IfModule mod_proxy.c>
ProxyRequests Off
ProxyPass /node http://localhost:3000/
</IfModule>
Express 应用如下所示:
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 不是一种选择。
标签: node.js apache express httpd.conf