0

I'm used to the typical lamp web hosting environment where you just click a few buttons in cpanel and your domain gets zoned and mapped to a folder within htdocs. I've been using node.js a lot and it doesn't seem as simple to do the same thing. If I had multiple node apps and I wanted to route domain1.com:80 and domain2.com:80 each to its own node app and port, how do I go about doing that? where do I start?

4

3 回答 3

2

这通常使用 nginx 完成。Nginx 是一个反向代理,一个你放在 node.js 前面的软件。

server {
    listen      80;
    server_name www.domain1.com;
    root /var/www/domain1;

    location / {
        proxy_pass http://localhost:1337; # this is where your node.js app_domain1 is listening
    }
}

server {
    listen       80;
    server_name www.domain2.com;
    root /var/www/domain2;

    location / {
        proxy_pass http://localhost:1338; # this is where your node.js app_domain2 is listening
    }
}

从这里:Nginx 同一 IP 上的不同域

于 2013-04-30T15:23:35.887 回答
1

如果您使用 Express,则可以在 Node 中设置虚拟域。

您用来启动服务器的代码看起来像这样。

var sys = require('sys'),
  express = require('express');

var app = express.createServer();

app.configure(function() {
  app.use(express.vhost('subdomain1.local', require('./subdomain1/app').app));
  app.use(express.vhost('subdomain2.local', require('./subdomain2/app').app));
  app.listen(3000);
});

然后您将app在每个子域中导出。

var app = express.createServer();
exports.app = app;

这是一篇文章,可以阅读更多关于Express.js 中的 vhost 的信息。

于 2013-04-30T16:15:37.197 回答
1

我不推荐 apache 来做这些,nginx 更适合 nodejs。

例如,您可以在端口 3000 和 3001 上运行应用程序,

然后将其代理到 mydomain1:80 和 mydomain2:80。

要在端口 80 上获取 mydomain1 和 mydomain2,这些都是关于 DNS 而不是 apache。

无法在同一端口上运行 apache/nginx 和您的节点 httpserver。会得到一个错误。

ps 我不确定你能不能做到这些@tipical lamp webhost

希望能帮助到你

于 2013-04-30T15:32:42.267 回答