在我的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