私のApache設定では、/node
のすべてのトラフィックをExpressサーバがリッスンしているポート3000
に転送しています。Expressルートを保存するためにApache ProxyPassを設定する方法
<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
が出ます。
Expressルートを維持するためにApache設定を更新する方法はありますか?
私はCentOS上でApache 2.4.6を実行しています。
これはヒントです:nginxプロキシノードを使用していますが、nginxを使用してapacheに接続することは考えられませんでしたか? –
ありがとう!しかし、残念なことにnginxを使用することは選択肢ではありません。 – stekhn