Multi-site support

CabloyJS supports the development of multi-site through the mechanism of multi-instance

See also: EggBornJS: Multi-instance

Instance Configuration

In Cabloy-CMS, the domain name example.com is generally left to the static parts, so a sub domain name needs to be assigned to the dynamic parts, such as admin.example.com

Name Domain Description
Static Parts example.com static files
Dynamic Parts admin.example.com backend API services

src/backend/config/config.prod.js

// instances
config.instances = [
  { subdomain: 'admin', password: '', title: '',
    config: {
      'a-base': {
        jsonp: { whiteList: 'example.com' },
      },
    },
  },
];
Name Description
subdomain subdomain
password the initial password of the user root
title website’s title
  • config:modules’s configuration in the instance

The configuration of module a-base is modified here:

Name Description
jsonp.whiteList whitelist for cors. only domain names in the whitelist can access the backend API services through ajax

Because the domain of static parts is different from the domain of dynamic parts , json.whitelist must to be set

Build Frontend

$ npm run build:front

Start Backend Service

$ npm run start:backend
  • Do not forget to create a MySQL database and configure src/backend/config/config.prod.js

Stop Backend Service

$ npm run stop:backend

Startup Parameters of Backend Service

build/config.js:

// backend
const backend = {
  port: 7002,
  hostname: '127.0.0.1',
};

Nginx Configuration

It is highly recommended to use nginx to host frontend static resources and to apply reverse proxy to backend service

Two nginx configuration files have been generated in the project root directory, which correspond to the dynamic and static parts of Cabloy-CMS respectively. Please modify them according to actual needs

Dynamic Parts: nginx.conf

server {

  listen 80;
  server_name admin.example.com;
  set $node_port 7002;

  root /Users/wind/Documents/temp/cabloy-cms/dist;

  location /public {
    root /Users/wind/cabloy/cabloy-cms;
    internal;
  }

  location  /api/ {
    proxy_http_version 1.1;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Host $server_name;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Host $http_host;
    proxy_set_header X-NginX-Proxy true;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_pass http://127.0.0.1:$node_port$request_uri;
    proxy_redirect off;
  }

}

Static Parts: nginx-cms.conf

server {

  listen 80;
  server_name example.com;

  root /Users/wind/cabloy/cabloy-cms/public/1/cms/dist;

}