如何设置Apache ProxyPass以保留Express路由

ste*_*khn 7 apache httpd.conf node.js express

在我的Apache配置中,我将所有流量转发/node到端口3000 Express服务器正在侦听的.

<IfModule mod_proxy.c>

  ProxyRequests Off

  ProxyPass /node http://localhost:3000/

</IfModule>
Run Code Online (Sandbox Code Playgroud)

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);
Run Code Online (Sandbox Code Playgroud)

当我将浏览器定向到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.

Yur*_*bin 9

/在主持人的末尾有一个额外的.尝试将其更改为:

ProxyPass /node http://localhost:3000
Run Code Online (Sandbox Code Playgroud)

  • 非常感谢。这就是诀窍。现在我会自己去面部护理。 (3认同)