Self host multiple sites


#1

I have a site, let’s call it example.co.uk, and want to host multiple vapid instances in the form:

Hosting a single instance reverse proxied (in Nginx) at example.co.uk is a piece of cake, but trying to expand that to run multiple sites on the same domain - or even a single instance in a sub-folder - has thus far been an exercise in futility.

I’ve been through a number of guides (e.g. https://github.com/vapid/vapid/wiki/Self‐hosting https://medium.com/@utkarsh_verma/configure-nginx-as-a-web-server-and-reverse-proxy-for-nodejs-application-on-aws-ubuntu-16-04-server-872922e21d38 http://www.nikola-breznjak.com/blog/javascript/nodejs/using-nginx-as-a-reverse-proxy-in-front-of-your-node-js-application/) and even concocted a basic node.js server to test my reverse proxy configs. After which I’ve begun to wonder if Vapid isn’t doing something a little odd?

Basically reverse proxying at the root works fine, e.g.

location / {
    proxy_pass http://localhost:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
}

but try as I might I can’t get it to work for locations like:

location /vapidsite01 {
    proxy_pass http://localhost:3001;
    ...
}
location /vapidsite02 {
    proxy_pass http://localhost:3002;
    ...
}
etc.

I can successfully browse to the individual instances (running with pm2) directly via the port, so I know they’re up and running ok. It’s just the reverse proxying that I seem to be having trouble with. I’ve tried many variations too, some with a trailing slash on proxy_pass, some with different proxy settings, etc. But I just seem to be making it fail in slightly different ways :slight_smile: - usually with a Vapid “Page Not Found” error, but sometimes with no images/css and sometimes with example.co.uk/vapidsite01/dashboard/ ending up at example.co.uk/. Basically if there’s a way to break it I’ve done it :laughing:

Does anyone have a similar setup successfully working, or have any ideas on what I might need to do to get it working?