Multiple Meteor apps on a single VPS?

I think I’ve got this figured out, I did a couple tests and they worked great. But I wanted to post the process here so others can maybe identify any gotchas I may have missed. Will gladly welcome any input from @arunoda. :smile:

Let’s say I have two small apps, app1 and app2, which I want to deploy as app1.com and app2.com. I have a single Ubuntu server running (currently just a virtual machine for testing).

In my first test (which failed), I installed nginx, Node, and MongoDB manually on the server. Locally, I ran mup init, configured mup.json, then ran mup deploy. I got some errors, something about fiber and npm. So I restored a server snapshot to revert all the manual installs I had done (except nginx).

Attempt #2: I configured mup.json to install Node and Mongo for me automatically. This worked great. The mup deploy process worked and I was able to surf to app1.com (I modified my /etc/hosts file). Works great!

The nginx conf file looks like this:

server {
  listen                *:80;

  server_name           app1.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:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header X-Forwarded-For $remote_addr;
  }
}

Not too sure what those headers are for, this is just a conf I grabbed from the official mup GitHub. It works though!

The second part of my test was to see if I could deploy app2 to the same server. For app2’s mup.json, I set it so it did not set up Node, Mongo, or PhantomJS, since they were already installed via app1. I also set the environment variable PORT to 3001 for app2 (app1 is on 3000). I deployed, and then made a new nginx conf file, app2.com.conf:

server {
  listen                *:80;

  server_name           app2.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;
  }
}

And this all seems to work great! I haven’t tested whether Kadira will work with two apps on the same server (I assume it will). But so far so good. And when I update app1 or app2, I just run mup deploy again and it pushes the new code to the server seamlessly.

Is this how it’s done? Am I doing anything wrong? Is there a better way?

6 Likes

A little bump of this thread to see if it will get some more views.

It’s a really interesting topic, I also came up with the same setup but I’m really not sure if this is the correct way to go, maybe it’s not ressource friendly or something.

Anyone ?

Lets be obnoxious and keep bumping this up until someone answers out of frustration. :wink:

Alright burn it to the ground then.

EDIT: the one being obnoxious and completely useless is you my friend :wink: :wink: :wink:

2 Likes

If you ask politely, I will explain to you what I said. :wink:

EDIT: I will explain it slowly so that all three of you get it. :slight_smile: :slight_smile: :slight_smile:

If it worked it worked. What’s the issue?

Although running the second app on port 3001 can be an issue because that’s the port meteor will use for mongodb by default if you run an instance on port 3000.

Not sure why that didn’t cause you issues.

Guessing this is a production server with mongo running on port 27017 (or compose.io or something), and not a dev environment. Certainly didn’t sound like a dev environment in the original post.

Thanks for the explanation Brent!