问题
How can Meteor handle multiple Virtual Hosts?
www.Some-Client-Domain.com --> www.Our-CName-URL.com --> Meteor app.
We need the Meteor app to serve the same site/app but with data specific to the original URL requested (Some-Client-Domain.com).
In our current prototype, we have NGINX in front of Rails, and there are a few different ways to do this, including wiring NGINX to the DB for definitions of the MANY Virtual Hosts. This works great, because if a new client signs up, we can update the DB, and then NGINX immediately knows about that Virtual Host without any further NGINX configuration.
How would this be accomplished in Meteor?
Thanks!
回答1:
Well, if you just ignore SSL for now (or want to figure out SSL for yourself later on), the below guide should work:
The basic idea
.. is to spawn multiple instances of the same application with different databases (mongo, the usual case) depending on the base URL.
We are going to use the following settings for the virtual hosts:
- Site #1 :
www.example1.com
- Meteor port:
3000
- MongoDB endpoint/url:
mongodb://localhost:27017/example1
- Meteor port:
- Site #2 :
www.example2.com
- Meteor port:
3001
- MongoDB endpoint/url:
mongodb://localhost:27017/example2
- Meteor port:
Preparing the meteor
instances
Install
foreman
viarubygems
:Create a
foreman
Procfile
file in your meteor project directory. Using the data above (don't include the bullets :D):web1: ROOT_URL=http://www.example1.com/ PORT=3000 MONGO_URL=mongodb://localhost:27017/example1 meteor
web2: ROOT_URL=http://www.example.com/ PORT=3001 MONGO_URL=mongodb://localhost:27017/example2 meteor
-OR- if you use the
meteor bundle
version:web1: ROOT_URL=http://www.example1.com/ PORT=3000 MONGO_URL=mongodb://localhost:27017/example1 node bundle/main.js
web2: ROOT_URL=http://www.example2.com/ PORT=3001 MONGO_URL=mongodb://localhost:27017/example2 node bundle/main.js
You can then run
foreman start
directly on the same directory (add a&
at the end to send to background). or you could install it as a service / upstart script viaforeman export
(this may vary for other linux distros, please refer to Foreman docs : http://ddollar.github.io/foreman/ ):sudo foreman export --app meteors --user <meteor files owner> upstart /etc/init
Preparing nginx
From here on out, the configuration for nginx should now be pretty straightforward:
server {
listen 80;
server_name www.example1.com example1.com;
location / {
proxy_pass http://localhost:3000;
proxy_set_header X-Real-IP $remote_addr;
}
}
server {
listen 80;
server_name www.example2.com example2.com;
location / {
proxy_pass http://localhost:3001;
proxy_set_header X-Real-IP $remote_addr;
}
}
Let me know if this works for you, although you mentioned that you already used SilkJS instead, I'll just leave this here for anyone else that's interested on the solution.
来源:https://stackoverflow.com/questions/13788146/how-can-meteor-handle-multiple-virtual-hosts