Search code examples
meteornginxreverse-proxymeteor-up

How to do a reverse-proxy with Nginx for multiple instance of Meteor


Problem

I'm trying to deploy multiple instance of Meteor on one single server web.

Every project have his own domain name (say 'A' -> 'A.com', 'B' ..), but server have a single web port:80. So I want to use Nginx to follow this article

Deployment

I'm using meteor-up (version mupx) to deploy each app. This is the cropped example of mup.json

{
  "appName": "A",
  "env": {
    "PORT": "3001",
    "ROOT_URL": "http://www.A.com"
  },
}

Nginx

This is my version of /etc/nginx/sites-available/A.com.conf

server {
  listen                *:80;

  server_name           A.com;

  access_log            /var/log/nginx/app.dev.access.log;
  error_log             /var/log/nginx/app.dev.error.log;

  location / {
    proxy_pass http://127.0.0.1:3001;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header X-Forwarded-For $remote_addr;
  }
}

Result

For every domain, when I call:

  :80   -> Ngninx Welcome page
  :3001 -> A.com
  :3002 -> B.com
 ..

How can I got the right site, based on domain name when I call the whatever:80 ?


Solution

  • So the solution is simply to add all possible version of the server name instead of only the domain name.

    Like so

    /etc/nginx/sites-available/A.com.conf

    server {
      listen                *:80;
    
      server_name           A A.com *.A.com;
    
      access_log            /var/log/nginx/app.dev.access.log;
      [...]