How To Set Up Django App on Apache With User With Their Own Subdomain And Their Unique Database on One Database Cluster?

Posted February 7, 2021 1.3k views
PythonBackupsDjangoDeploymentDigitalOcean Managed PostgreSQL DatabaseUbuntu 20.04StartupsBuilding a SaaS

My idea is to deploy a django app on an Apache Server Droplet, which can have my users access the app with each user with their own unique subdomain example:, and so on, and each with their own unique database in one DigitalOcean Database Cluster. So that when I upload the source code of the app, all users will get the same updated version with their data in the database intact.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Hi there,

What I could suggest is using Apache Virtual Hosts so that you could host multiple sites on the same server. You can follow the steps on how to do that here:

Regarding the databases, you will be able to create separate databases for your managed cluster directly via your DigitalOcean Control panel and then change the database connection strings accordingly for each application.

Hope that this helps.

by Brennen Bearnes
The Apache web server is the most popular way to serve web content on the internet. Apache has the ability to serve multiple domains from a single server by using a mechanism called "virtual hosts". If a virtual host is configured correctly for each domain, the web server can correctly route traffic to the appropriate files based on the domain name requested. In this guide, we'll demonstrate how to configure Apache virtual hosts on an Ubuntu 16.04 server.
  • Thank you so much @bobbyiliev for your reply. I almost thought i won’t get any.
    I have read and understood the reference but i still have some concerns, the 1st is that can I use this method in production? and if yes, how do i deal with ServerAliases in the apache conf? for instance. like i said that I want each of my users to have access to the app in a subdomain like, with each getting the same version update from a single github repo. the 2nd concern is that i have to restart the apache service in order for the new users’ conf to take effect, would that be good for active users?

    It is a Django App and i want an auto deploy if that’s important to know.

    What do you think about Docker containers as an alternative?

    • Hi there,

      What I could suggest is that if each application is going to be connecting to a different backend service, is to use separate Apache Vhost files for each domain name.

      If all domains would be connecting to the same backend service, then you could use the ServerAliases approach instead.

      Regarding restarting the Apache service, what you could do is to just do a reload rather then restart, that way there should be no noticeable downtime for the active users.

      Yes, using Docker containers also sounds like a plan. Here is a quick guide on how to host multiple Docker containers on the same server with Nginx as the reverse proxy:

      Hope that this helps!