Hello, I’m pretty new to web development and Frappe, and I’m trying to grasp the concept of multi-tenancy better. I want to clarify if multi-tenancy is even possible in development mode.
I tried setting up 2 sites on a single bench (all still in development mode) although I’m using nginx outside of Bench to publish the site. I tried to setup a port-based multitenancy to run both sites by tinkering with the Procfile as shown below.
When I ran bench start, it does run both ports and I’m able to access both domains. However, the problem is, both domains will point to the site listed in the currentsite.txt file, so the result is I have 2 domains pointing to 1 site because currentsite.txt only accepts 1 site (as far as I have tested).
What I wanted is to have 2 sites running simultaneously, and the 2 domains I have will each point to a different site (domain1 point to siteA, while domain2 point to siteB).
I have tried many solutions to work around this as I read that multi-tenancy expects sites to be ran on production mode, and neither bench serve nor bench start have an option to run a specific site.
So, what I want to clarify is:
Is multi-tenancy only works for sites in production mode as it relies on bench’s nginx and supervisor?
Is the only solution to this is to setup a new bench instance if I want to run both sites simultaneously on development mode?
I’ll appreciate it if anyone have any knowledge about this that you can share with me as I still have many holes in my understanding of Frappe that I’m trying to fill
You should create two sites with this command and the appriate options (e.g. your ports – or maybe not ports, after all, since you can differentiate the sites via your domain names):
Thank you, this solution works and I figured out some of the limitations of running 2 sites on the same bench when trying out your solution (the important one is I can’t seem to keep both sites running by sending the bench serve processes to the background)
I have now used 2 different benches to run 2 sites simultaneously as you suggested and it’s able to keep running when the processes is sent to the background
It could work with DNS based multi-tenancy. I’ve been doing it for a few years now. You do need nginx or other equivalent web servers for this though.
Just create *.localhost name servers in nginx config. Like erpnext1.localhost and erpnext2.localhost. With these, you don’t need to add etc host file mappings. *.localhost always resolve to 127.0.0.1. You have to pass correct X-Frappe-Site-Name header so that frappe properly resolve to specific site. Here a sample config from my development setup.
web: bench serve --port 8000 //By default added
web2: bench --site sitename.local serve --port 8001 //change the key to web2 any increment, change the port to something different
web3: bench --site sitename2.local serve --port 8002
Add site.name to host file and it should be accessible on browser using the following url:
sitename.local:8001
sitename2.local:8002
This setup will work without adding custom domain. Is there any point adding custom domain in dev setup?