How to handle more than one domain?
문제
I need to use Node.JS for 3 domains. How can I do it? At the moment I have one application that binds port 80, how to support more than one domains? I also use cluster module that forks my application in 3 processes.
해결책
Probably best way, use connect vhost, which is a connect module.
Or: you can rewrite your URLs with a global URL handler, and then write your constraints based on the rewritten 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(){
});
다른 팁
Use https://github.com/nodejitsu/node-http-proxy.
You need to run the reverse proxy on port 80 ( assuming you are using HTTP and not HTTPS) and then the request be routed to different services ( i.e. node servers.). The actual node server will be using non-standard ports to listen.
e.g
Service A (for domain A ) - 8001
Service B (for domain B ) - 8002
Service C (for domain C ) - 8003.
제휴하지 않습니다 StackOverflow