views:

166

answers:

2

I have two distinct Django "projects", which I want to run on a single domain using mod_wsgi. With mod_python, I believe there was a way to do this, where certain url paths would be mapped to one Django project, and other paths mapped to the other project, all at the server level.

Is it possible to do this with mod_wsgi, and if so, how?

Things I have considered: what goes in the Apache virtual host description, what goes into application.wsgi files, etc. But I haven't figured out exactly how to do this.

Thanks!

+1  A: 

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.

Daniel Roseman
Thanks! This worked! So simple, don't know why I didn't think of it...
A: 

Hi expaando,

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
Thanks, Jens - but I don't want separate subdomains (if possible). I want a single domain for multiple projects, but with urls mapped to the appropriate project at the server level.
So you want *www.yourdomain.com/project1/* and *www.yourdomain.com/project2/* ??
Jens
Yes, pretty much. (Actually, I want project1 to be www.yourdomain.com and project2 to be www.yourdoamin.com/project2...)