skip to Main Content

I have 3 applications(app1, app2, app3) in one django project(mydjango), each of these apps have different usage and different domains to be served (app1.domain.com; app2.domain.com; app3.domain.com) as it is single django project we have only one manage.py file.

I am trying to deploy these using apache2 web server and all these 3 apps uses same virtualenv(using pyenv) and same mysql database with different tables.

Now the problem is how to point these 3 domains to thier specific apps,

can anyone please suggest a solution

I tried few methods that suggested by chatgpt and other sources/articles from web,

<VirtualHost *:80>
    ServerName domain1.com
    ServerAlias www.domain1.com
    DocumentRoot /path/to/your/project/<project_name>

    WSGIDaemonProcess domain1.com python-path=/path/to/your/project/<project_name>:/path/to/your/project/<virtualenv_name>/lib/python3.X/site-packages
    WSGIProcessGroup domain1.com
    WSGIScriptAlias / /path/to/your/project/<project_name>/app1/wsgi.py

    <Directory /path/to/your/project/<project_name>>
        Require all granted
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName domain1.com
    ServerAlias www.domain1.com
    DocumentRoot /path/to/your/project/<project_name>

    WSGIDaemonProcess domain1.com python-path=/path/to/your/project/<project_name>:/path/to/your/project/<virtualenv_name>/lib/python3.X/site-packages
    WSGIProcessGroup domain1.com
    WSGIScriptAlias / /path/to/your/project/<project_name>/app2/wsgi.py

    <Directory /path/to/your/project/<project_name>>
        Require all granted
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName domain1.com
    ServerAlias www.domain1.com
    DocumentRoot /path/to/your/project/<project_name>

    WSGIDaemonProcess domain1.com python-path=/path/to/your/project/<project_name>:/path/to/your/project/<virtualenv_name>/lib/python3.X/site-packages
    WSGIProcessGroup domain1.com
    WSGIScriptAlias / /path/to/your/project/<project_name>/app3/wsgi.py

    <Directory /path/to/your/project/<project_name>>
        Require all granted
    </Directory>
</VirtualHost>

here the suggested configuration shows 3 different "wsgi.py" files for 3 apps, but mydjango project created just one wsgi.py

enter image description here

Now how should i modify the apache configuration.

can anyone suggest some solution.

Thanks in advance.

2

Answers


  1. What I would recommend is that you create other projects, since if they work differently and you exclusively want them to be in different domains, then it is my recommendation to have different projects, since Django responds under the same URL, what changes is the endpoint. Create 3 projects and in each one apply the Model, which you will use, and then the urls that you will work with, you will have 3 wsgi.py files and you will be able to link them individually to each domain separately.

    Login or Signup to reply.
  2. You could think of Django apps as ‘modules’ and not as an actual standalone web app, you should probably create a different project for each web app you want to run and use apps to internally organize different elements and working parts of the application.

    You could use Django’s poll app as an example of how apps are used inside a Django project.

    https://docs.djangoproject.com/en/4.2/intro/tutorial01/#creating-the-polls-app

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search