这是官方文档,
https://github.com/frappe/bench/wiki/Multitenant-Setup
Multitenant Setup
多租户(站点)设置
Assuming that you've already got your first site running and you've performed the production deployment steps, this section explains how to host your second site (and more). Your first site is automatically set as default site. You can change it with the command,
假设第一个站点已在生产模式运行,第一个站点已被自动设为默认站点,使用以下命令可切换默认当前站点
bench use 站点名
Port based multitenancy
基于端口的多站点
You can create a new site and make run it on a different port (while the first one runs on port 80).
创建新站点后需指定端口,默认第一个站点占用标准80端口
Create a new site
创建新站点
bench new-site 站点名
Set port
设置端口
bench set-nginx-port 站点名 82
Re generate nginx config
重新生成nginx配置
bench setup nginx
Reload nginx
重新加载nginx
sudo service nginx reload
DNS based multitenancy
子域名多站点
You can name your sites as the hostnames that would resolve to it. Thus, all the sites you add to the bench would run on the same port and will be automatically selected based on the hostname.
创建站点时用子域名作为站点名,所有站点都运行在相同端口,站点通过子域名匹配。
DNS based multitenancy mode is disabled by default, you can switch it on / off using the command,
默认子域名多站点功能未启用,可使用以下命令开启
bench config dns_multitenant on
To make a new site under DNS based multitenancy, perform the following steps.
步骤如下
Create a new site
创建新站点
bench new-site 站点名
Re generate nginx config
重新生成nginx配置,重新加载,重启服务
bench setup nginx
Reload nginx
sudo service nginx reload
Note : For "DNS based multitenancy", currentsite.txt in frappe-bench/sites/ should be empty.
注: 启用子域名多站点需将frappe-bench/sites/目录下currentsite.txt文件中当前站点清空
本质上的技术原理就是利用nginx做反向代码,即通过nginx的配置文件里将子域名或端口时映射到了站点对应的目录,即数据库。熟nginx的,可以手工调整配置文件实现。
这个论坛帖子也值得参考。