Meteor.js和Apache / Nginx在同一服务器上提供不同的域名

时间:2013-12-14 15:20:07

标签: node.js apache nginx meteor npm

我们如何配置服务器使用Meteor.js和http://domain1.com使用nginx / apache来服务http://domain2.com

2 个答案:

答案 0 :(得分:3)

您可以使用node-http-proxy脚本执行此操作或使用nginx。

示例node-http-proxy脚本。确保使用caronte分支将允许websockets与流星一起使用而不会长时间轮询:

示例node.js脚本

var httpProxy = require('http-proxy');

httpProxy.createServer({
  router: {
    'domain1.com': 'localhost:3000' //Meteor port & host
    'domain2.com': 'localhost:8000' //Apache port & host
  }
}).listen(80);

所以上面的内容将在端口80上运行。你可以在端口3000上运行meteor,在端口8000上运行apache / nginx。

代理将检查域名主机名,如果它的domain1.com,它将作为localhost的透明代理:3000

答案 1 :(得分:1)

另一种方法是让nginx处理代理并使用虚拟主机来分离流量。

您需要nginx 1.4.3或更新版本来代理websockets,以下配置将执行此操作:

<强> /etc/nginx/conf.d/upgrade.conf

map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

<强>的/ etc / nginx的/启用的站点 - /流星

server {
    server_name domain1.com;

    # add_header X-Powered-By Meteor; 

    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
    }
}

并且您的Apache站点的nginx配置将与通常相同,但使用server_name domain2.com;或您想要命名的任何内容。

相关问题