Anyone running multiple KeystoneJS instances on the same server?

422 views
Skip to first unread message

Chris Troutner

unread,
Feb 9, 2017, 12:52:05 PM2/9/17
to Keystone JS
Has anyone out there successfully set up a server to run multiple instances of KeystoneJS on the same OS? This should be possible using Docker containers or routing using nginx, but I don't have any experience with either. If anyone has pulled this off, please raise your hand. I'd love to hear about your setup and how you went about doing it. 

At the moment I use Digital Ocean Droplets to run my KeystoneJS sites. One Droplet per server. But I got to reading a whitepaper on Docker and it's got my wheels spinning on how I might be able to build a shared server and run site more efficiently.

-Chris Troutner

Vladimir Ilic

unread,
Feb 10, 2017, 12:35:26 PM2/10/17
to Keystone JS
Hello Chris,
when you say "multiple instances" do you think:
 - same content / domain (for example all of them are behind load balancer and serve same content). In general you want to scale horizontally.
 - different content / domain (each for different end point, no load balancer in front).

For a first case, it is very easy to implement using dockers. It is up to environment how you want to deploy. For example on a same server (your local or Amazon EC2 as example) you can add HA proxy in front of your instances. Here is example docker-compose.yml file:

myapp:
  image: ${MY_APP_DOCKER_IMG}
  environment:
    - NODE_ENV=${NODE_ENV}
  volumes:
    - /tmp:/tmp
  restart: always

haproxy:
  image: tutum/haproxy
  links:
    - myapp
  environment:
    - BACKEND_PORT=8080
  ports:
    - "80:80"
  restart: always


You can start with line like this one:

docker-compose -f docker-compose.yml  scale myapp=3

This will start 3 docker containers with myapp. HA Proxy will connect and load balance  between your docker instances. See https://hub.docker.com/r/tutum/haproxy/ for configuration details.

Chris Troutner

unread,
Feb 14, 2017, 4:11:36 PM2/14/17
to Keystone JS
Thanks Vladimir! Between this and the advice I got on the Slack channel, I've got a lot of ideas to research.

Chris Troutner

unread,
Feb 15, 2017, 5:22:26 PM2/15/17
to Keystone JS
Thank you Vladimir and also a big thank you Jake Stockwin, who helped me out on the KeystoneJS slack channel.

It turned out I didn't need Docker at all, just NGINX in order to run multiple instances of KeystoneJS to server multiple domains. I still think a lot of the virtualization technology in Docker is cool and makes sense for certain business cases, but I'm glad not to need the extra overhead that virtualization adds.

After Jake pointed me in the right direction with setting up NGINX as a proxy server, I discovered this awesome tutorial that had an example configuration file me to use:

For reference, if anyone else wants to do this same there, here is the config file I'm using to run two domains off the save Digital Ocean Droplet, both running their own instance of KeystoneJS. One runs on port 3001, the other on port 3002. NGINX handles traffic on port 80 and routes it to the proper port based on the requested domain. NGINX also serves up the static content from the /public directory as it's supposed to be better at that than node/express is.

# This server configuration is for running multiple instances of KeystoneJS.
# Configuration script comes from tutorial on ksloan.net:

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        #root /var/www/html;
root /home/trout/connextcmsdemo/myCMS/public;

        server_name demo.connextcms.com;

        location / {
try_files $uri @backend;
        }
location @backend {
access_log off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_hide_header X-Frame-Options;
}
}

server {
listen 80;
#server_name skagitholiday.com;
#location / {
# proxy_pass http://127.0.0.1:3002;
#}
#root /var/www/html;
root /home/trout/skagitholiday/myCMS/public;

server_name skagitholiday.com;

location / {
try_files $uri @backend;
}
location @backend {
access_log off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_hide_header X-Frame-Options;
}
}




Reply all
Reply to author
Forward
0 new messages