Skip to content

setup multitenancy for ERPNext 3

Pratik Vyas edited this page Mar 10, 2014 · 2 revisions

Prepare

  • Install ERPNext and change to erpnext directory
  • create sites directory
mkdir sites
  • Add sites_dir to conf.py
sites_dir = '/path/to/erpnext/sites'
  • Move the existing site to sites directory
mkdir -p sites/{{ your_site_name }}/
mv public sites/{{ your_site_name }}/public
  • write site_config.json
edit sites/{{ your_site_name }}/site_config.json

and add the following content

{
 "db_name": "get db_name from conf.py",
 "db_password": "get db_password from conf.py"
}

Add a second site

./lib/wnf.py --install dbname --site name

Updating ERPNext

./lib/wnf.py --pull origin master
./lib/wnf.py --build
./lib/wnf.py --latest --site site1
./lib/wnf.py --latest --site site2
#...

Change in nginx config

worker_processes 1;

user www-data www-data;
pid /var/run/nginx.pid;
error_log /tmp/nginx.error.log;

events {
    worker_connections 1024;
    accept_mutex off;
}


http {
    include mime.types;

    default_type application/octet-stream;
    access_log /tmp/nginx.access.log combined;
    sendfile on;
    types_hash_max_size 2048;

    upstream erpnext {
        server 127.0.0.1:8000 fail_timeout=0;
    }

    server {
        listen 80 default;
        client_max_body_size 4G;
        server_name localhost;
        keepalive_timeout 5;
        sendfile on;
        root /path/to/erpnext/sites;

        location /private/ {
            internal;
            try_files /$uri =424;
        }

        location / {
            try_files /$host/public/$uri @magic;
        }

        location @magic {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Use-X-Accel-Redirect True;
            proxy_set_header Host $http_host;
            proxy_read_timeout 120;
            proxy_redirect off;
            proxy_pass  http://erpnext;
        }
    }
}

###Notes

  • Do not remove db_name and db_password from conf.py (at least one db config is required for asset building.
  • The site name should be same as the Host HTTP header. IE, if you want to host example.com, site name has to be example.com and the HTTP Host header has to be example.com. Going to http://ip_address/ will not work!