I just created a small meteor project (meteor run --port 4000) and pointed nginx with several server names to it (you need to change to your FQDN)
server {
server_name domain-a.example.com domain-b.example.com domain-c.example.com;
root /Users/user/Meteor/domains/public;
location / {
proxy_pass http://127.0.0.1:4000;
proxy_http_version 1.1;
proxy_read_timeout 36000s;
proxy_send_timeout 36000s;
proxy_set_header Upgrade $http_upgrade; # allow websockets
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Forwarded-For $remote_addr; # preserve client IP
proxy_set_header Host $host;
#
#proxy_set_header Connection "";
#proxy_redirect off;
#chunked_transfer_encoding off;
#
# this setting allows the browser to cache the application in a way compatible with Meteor
# on every applicaiton update the name of CSS and JS file is different, so they can be cache infinitely (here: 30 days)
# the root path (/) MUST NOT be cached
if ($uri != '/') {
expires 30d;
}
}
}
and it works pretty much as expected.
I get the domain with document.location.host.split('.').shift() on the client.
I created a little method that updates the domain per connection so the server knows which domain a connection is on.
Meteor.methods({
domain(domain){
var c = DomainConnections.findOne(this.connection.id);
if (c) {
DomainConnections.update(c._id, { $set: { domain: domain } })
} else {
c = { _id: DomainConnections.insert({ _id: this.connection.id, domain: domain }) }
}
return c._id;
}
});
Meteor.onConnection(function (connection) {
const connectionId = connection.id;
connection.onClose(function () {
let c = DomainConnections.remove(connectionId);
console.log(`onClose ${connectionId} removed ${c}`);
});
});
Meteor.startup(function () {
//
// clear DomainConnections when server starts
//
DomainConnections.remove({});
});
Meteor.publish('domain', function () {
var c = DomainConnections.findOne( this.connection.id );
if(!c) {
console.log(`inserted ${DomainConnections.insert({ _id: this.connection.id, domain:'unknown'})}`);
}
return DomainConnections.find({ _id: this.connection.id });
});