How do I deploy multiple meteor apps to the same digital ocean droplet using mupx & docker and using multiple domain names?


#1

I’m just wondering if anyone has tried this. Seems like a $5/month digital ocean droplet should be able to support a dozen different toy apps in various stages of development. I’m guessing I can just use different ports for the three apps when I deploy with mupx and then configure my droplet to support multiple domains somehow. Has anyone tried this?


#2

Yes. I have two dev apps and a live one, runs great. I don’t have much traffic there now, so I don’t know what the scale limit is. I host the database and the app on the same $5 server.


How to programatically create a Meteor instance with a subdomain
#3

do you use mupx? If so, how do you configure it?


#4

I use mup, not mupx.

First app mup.json

{
  // Server authentication info
  "servers": [
    {
      "host": "Domains",
      "username": "root",
      "pem": "/root/.ssh/id_rsa",
      "sshOptions": { "Port" : 22 }
    }
  ],

  // Install MongoDB in the server, does not destroy local MongoDB on future setup
  "setupMongo": true,

  // WARNING: Node.js is required! Only skip if you already have Node.js installed on server.
  "setupNode": true,

  // WARNING: If nodeVersion omitted will setup 0.10.33 by default. Do not use v, only version number.
  "nodeVersion": "0.10.36",

  // Install PhantomJS in the server
  "setupPhantom": true,

  // Application name (No spaces)
  "appName": "myApp",

  // Location of app (local directory)
  "app": "/home/domains/Meteor/myApp",

  // Configure environment
  "env": {
    "PORT": "45180",
    "ROOT_URL": "https://myApp.domain.com"
  },

  // Meteor Up checks if the app comes online just after the deployment
  // before mup checks that, it will wait for no. of seconds configured below
  "deployCheckWaitTime": 15
}

Second app mup.json

{
  // Server authentication info
  "servers": [
    {
      "host": "Domains",
      "username": "root",
      "pem": "/root/.ssh/id_rsa",
      "sshOptions": { "Port" : 22 }
    }
  ],

  // Install MongoDB in the server, does not destroy local MongoDB on future setup
  "setupMongo": true,

  // WARNING: Node.js is required! Only skip if you already have Node.js installed on server.
  "setupNode": true,

  // WARNING: If nodeVersion omitted will setup 0.10.33 by default. Do not use v, only version number.
  "nodeVersion": "0.10.36",

  // Install PhantomJS in the server
  "setupPhantom": true,

  // Application name (No spaces)
  "appName": "myApp1",

  // Location of app (local directory)
  "app": "/home/domains/Meteor/myApp1",

  // Configure environment
  "env": {
    "PORT": "45280",
    "ROOT_URL": "https://myApp1.domain.com"
  },

  // Meteor Up checks if the app comes online just after the deployment
  // before mup checks that, it will wait for no. of seconds configured below
  "deployCheckWaitTime": 15
}

Then I use nginx to proxy the traffic to the correct ports from port 443 and 80

server {
    listen 80;
    server_name myApp.domain.com;
	return 301 https://myApp.domain.com$request_uri;
}

server {
	
	listen 443 ssl;
    server_name myApp.domain.com;
    ssl_certificate /etc/nginx/ssl/ssl-bundle-myApp-domain-com.crt;
    ssl_certificate_key /etc/nginx/ssl/myApp_domain_com.key;
    
    location / {
        proxy_pass http://myApp;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $http_host;
        
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forward-Proto http;
        proxy_set_header X-Nginx-Proxy true;
        
        proxy_redirect off;
        
    }
    location /images {
            alias /opt/myApp/app/programs/web.browser/app/images;
            access_log off;
            expires max;
    }
    
    location /fonts {
        alias /opt/myApp/app/programs/web.browser/app/fonts;
        access_log off;
        expires max;
    }
    
    location "^/[a-z0-9]{40}\.(css|js)$" {
        root /opt/myApp/app/programs/web.browser;
        access_log off;
        expires max;
    }
}

And the same thing as above for a conf file for the other apps. I’m using subdomains or domains to point to different apps.


#5

This was of great help for me:

http://odlaner.com/host-multiple-meteor-and-ghost-instances-on-digitalocean/


#6

Where did you save the nginx conf ?

This is what i am planning.

Server 1, https://mydomain.com - Fronend app hosted here

Server 2, https://admin.mydomain.com - Admin hosted here

I’m planning to use LetsEncrypt for https
So two servers how do I set it up please ? Can u help ?


#7

If you use mupx you can specify the SSL and just have two instances on the same machine via different url and ports. I’ve got a main url and a screening.mydomain.com for screening purposes


#8

What if I need to deploy 2 meteor apps on the same mongodb instance? Basically I want to try 2 different UI on the same application (version 1 and version 2).
I use mup and digital ocean.


#9

I do this from my production and dev environments – simply have both Meteor apps use the same MONGO_URL.


#10

Great. Do you know if I can configure mup setting to do that for me on each application?


#11

Yes, the MONGO_URL is specified in the mup.json file – just include the same MONGO_URL in both mup.json files for the two apps. I assume you are using an external MongoDB, so in mup.json set setUpMongo to false.


#12

It’s a test machine for now, so everything on the same machine on DO.
Do you know what value should MONGO_URL have if my MongoDB is on the same machine as the Meteor application?


#13

I use

"MONGO_URL": "mongodb://127.0.0.1:27017/appName"

Works like a charm


#14

Hi guys! I deployed two apps on two different domains with MUPX and everything cool except the one issue:

APP #1

    "env": {
        "PORT": "3000",
        "ROOT_URL": "http://firstdomain.com"
    },

APP #2

    "env": {
        "PORT": "4000",
        "ROOT_URL": "http://seconddomain.com"
    },

The issue: If I go to “http://firstdomain.com:4000” I see second app instead of first app and If I go to “http://seconddomain.com:3000” I see first app instead of second app. What should I do to prevent access to second domain through the first one and otherwise?


#15

#16

Should I change the application name in mup.json?


#17

ADD ON TO THE PREVIOUS REPLY – I mean, I need to deploy 2 different versions of the same app, but I suppose that mup uses the appName to create a directory structure for each deployment on the server.


#18

Yes just create one mup for ‘appName1’ and another for ‘appName2’ both can have the same repository providing exactly the same files just two configurations. You could also use a settings file maybe to enable debugging info on one (i assume you want a screening and live setup?)

Hope u all the best with it