Reputation: 1033
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!
Upvotes: 13
Views: 3235
Reputation: 21540
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:
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.
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.
Upvotes: 8
Reputation: 600026
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.
Upvotes: 8