multiple django sites with apache & mod_wsgi multiple django sites with apache & mod_wsgi django django

multiple django sites with apache & mod_wsgi


Your ServerName/ServerAlias directives are wrong. ServerName should be hostname. You probably should just delete ServerAlias.

Then just do the obvious and duplicate VirtualHost/Listen directives, just changing the port number and locations of scripts in the file system.

Finally, do not set DocumentRoot to be where your Django code is as it makes it easier to accidentally expose your source code to download if you stuff up Apache configuration. So, just remove DocumentRoot directive from VirtualHost for Django sites.

Listen 80<VirtualHost *:80>ServerName www.example.comWSGIScriptAlias / /opt/django/site1/apache/django.wsgiAlias /media /opt/django/site1/media/staticsAlias /admin_media  /home/myuser/Django-1.1/django/contrib/admin/media<Directory opt/django/site1/apache>Order allow,denyAllow from all</Directory><Directory /home/myuser/Django-1.1/django/contrib/admin/media>Order allow,denyAllow from all</Directory></VirtualHost>Listen 8080<VirtualHost *:8080>ServerName www.example.comWSGIScriptAlias / /opt/django/site2/apache/django.wsgiAlias /media /opt/django/site2/media/staticsAlias /admin_media  /home/myuser/Django-1.1/django/contrib/admin/media<Directory opt/django/site2/apache>Order allow,denyAllow from all</Directory><Directory /home/myuser/Django-1.1/django/contrib/admin/media>Order allow,denyAllow from all</Directory></VirtualHost>Listen 8090<VirtualHost *:8090>ServerName www.example.comWSGIScriptAlias / /opt/django/site3/apache/django.wsgiAlias /media /opt/django/site3/media/staticsAlias /admin_media  /home/myuser/Django-1.1/django/contrib/admin/media<Directory opt/django/site3/apache>Order allow,denyAllow from all</Directory><Directory /home/myuser/Django-1.1/django/contrib/admin/media>Order allow,denyAllow from all</Directory></VirtualHost>

I have also add missing Directory directive for allowing access to static files. You should review paths however.

Make sure you read:

http://code.google.com/p/modwsgi/wiki/IntegrationWithDjangohttp://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines#Hosting_Of_Static_Files

for further information.


UPDATE 1

BTW, since you are using PHP in same Apache, you would be much better off using mod_wsgi daemon mode and push each Django instance out into its own separate process. That allows those processes to be multithreaded, even though main Apache processes are forced to be single threaded because of PHP. End result will be much much less memory being used than if running multiple Django instances in each process under embedded mode with prefork MPM. Your Django code just needs to be thread safe. Configuration in addition to above would be to add WSGIDaemonProcess/WSGIProcessGroup to each Django VirtualHost, where name of daemon process group is different for each VirtualHost.

<VirtualHost *:80>WSGIDaemonProcess site1 display-name=%{GROUP}WSGIProcessGroup site1... existing stuff</VirtualHost><VirtualHost *:8080>WSGIDaemonProcess site2 display-name=%{GROUP}WSGIProcessGroup site2... existing stuff</VirtualHost><VirtualHost *:8090>WSGIDaemonProcess site3 display-name=%{GROUP}WSGIProcessGroup site3... existing stuff</VirtualHost>

This also allows you to more easily restart each Django instance without restart whole of Apache. Read:

http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide#Delegation_To_Daemon_Processhttp://code.google.com/p/modwsgi/wiki/ReloadingSourceCode


Putting all virtualHost configuration in one place works fine, but Debian has its own concept by separating them in a file for each site in /etc/apache2/sites-available, which are activated by symlinking them in ../sites-enabled. In this way a server-admin could also assign separate access rights to the config file for each of the site-admin unix users, scripts can check if a site is active etc.

Basically it would be nice to have one central howto for Django-Admin installations, the current multitude of separate docs, links and blog articles is not really helpful for the proliferation of Django.