我需要为 3 个域使用 Node.JS。我该怎么做?目前我有一个应用程序绑定(bind)了80端口,如何支持多个域? 我还使用集群模块将我的应用程序分成 3 个进程。
最佳答案
可能是最好的方法,使用 connect vhost , 这是一个连接模块。
或者:您可以使用全局 URL 处理程序重写您的 URL,然后根据重写的 URL 编写您的约束:
app.get('*', function(req, res, next){
if(req.headers.host === 'domain1.com')
req.url = '/domain1' + req.url;
else if(req.headers.host === 'domain2.com')
req.url = '/domain2' + req.url;
next();
})
.get('/domain1/index', function(){
})
.get('/domain2/index', function(){
});
关于node.js - 如何处理多个域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8324126/