[Django]-Django (wsgi) and WordPress coexisting in Apache virtualhost

5👍

Replace:

DocumentRoot /var/empty

with:

DocumentRoot /home/zach/projects/python/myproject/wordpress

Remove:

Alias / /home/zach/projects/python/myproject/wordpress/

Replace:

WSGIScriptAlias /accounts /home/zach/projects/python/myproject/app/privio.wsgi
WSGIScriptAlias /studio /home/zach/projects/python/myproject/app/privio.wsgi

with:

WSGIScriptAliasMatch ^(/(accounts|studio)) /home/zach/projects/python/myproject/app/privio.wsgi$1

In other words, use DocumentRoot to refer to wordpress that needs to be at root of site and not Alias directive.

The WSGIScriptAliasMatch is so Django itself thinks it is still mounted at root site even though only nominated sub URLs of it are actually passed through. This simplifies things for urls.py.

Note that the $1 at end of WSGI script path is important, so don’t leave it off.

1👍

Paging Graham Dumpleton 🙂

I’d venture a guess that the line

Alias / /home/zach/projects/python/myproject/wordpress/

overrides everything below it. Therefore any requests to /accounts will be processed by the wordpress application rather than by the Django application.

From the documentation:

Mounting At Root Of Site

If instead you want to mount a WSGI application at the root of a site, simply list ‘/’ as the mount point when configuring the WSGIScriptAlias directive.

WSGIScriptAlias / /usr/local/www/wsgi-scripts/myapp.wsgi

Do note however that doing so will mean that any static files contained in the DocumentRoot will be hidden and requests against URLs pertaining to the static files will instead be processed by the WSGI application.

Leave a comment