2015-10-15 23 views
5

在我的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/routehttp://myserver.com/node/1210時,出現錯誤Cannot GET //route

任何想法如何我可以更新我的Apache配置,以保持Express路線?

我在CentOS上運行Apache 2.4.6。

+0

這只是一個提示:它使用nginx代理節點,沒有考慮過使用nginx到apache inves? –

+0

謝謝!但不幸的是使用nginx不是一個選項。 – stekhn

回答

8

您的主機末端還有一個/。嘗試更改爲:

ProxyPass /node http://localhost:3000 
+0

非常感謝。那就是訣竅。現在我將自己去臉上。 – stekhn