[Fixed]-Multiple django projects, mod_wsgi, single domain

8👍

This shouldn’t be complicated. It’s just a matter of setting the WSGIScriptAlias directive – you’ll need two of these, one for each path, each pointing to a separate .wsgi file which contains your project settings.

8👍

I am also working with Apache and I am running multiple Django projects with one domain. There are only two things you have to do:

  1. Modify your Virtual Host files

    Since I am using Debian I have one vhost file for each domain I am hosting. In your vhost file you should have multiple vhost sections. One for each project. Inside these sections you can define WSGIScriptAlias.

    <VirtualHost *:80>
      ...
     WSGIScriptAlias / /path/to/project1.wsgi
     ...
    </VirtualHost>
    
    <VirtualHost *:80>
      ...
      WSGIScriptAlias / /path/to/project2.wsgi
      ...
    </VirtualHost>
    

    Of course you have to add all the other necessary information. Project 1 and 2 certainly will have different sub-domains. For example project1.yourdomain.com and project2.yourdomain.com.

  2. Write your *.wsgi files

    There are many ways to write and store *.wsgi files. I don’t know any best practices. In my case I store them in my project folder.

    This is an example:

    import os
    import sys
    os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
    sys.path.append('/path/to/your/project')
    import django.core.handlers.wsgi
    application = django.core.handlers.wsgi.WSGIHandler()
    

    I’ve seen a lot of other *.wsgi files with more “magic”. But this should get you started. You can find a lot of examples all over the internet.

Hope that answers your question. Don’t be afraid to ask more questions.

👤Jens

Leave a comment