[Answered ]-Multiple Django projects apache virtual hosts

1👍

The topic of why your requests may end up being handled by the wrong Django instance has been documented in detail in the blog post at:

There are multiple possible situations described in that blog post as to what can go wrong.

In your case it sounds like the virtual host for the second, if in a separate file, may not have been enabled and so the web server is not even reading the file. The consequence is that Apache will send all requests to the first VirtualHost if it can’t find an appropriate match using name based virtual hosting.

I would suggest adding a syntax error to the second virtual host (‘xxx’ on a line by itself) and see if Apache outputs an error when trying to start. This will confirm whether file being read.

1👍

<VirtualHost *:80>

ServerName www.example1.com
ServerAlias example1.com
ServerAdmin admin@example1.com

DocumentRoot "/var/www/example1"

WSGIScriptAlias / /var/www/example1/example1/wsgi.py
WSGIDaemonProcess www.example1.com python-path=/var/www/example1:/usr/local/lib/python2.7/site-packages

<Location />
WSGIProcessGroup www.example1.com
</Location>

<Directory /var/www/example1>
<Files wsgi.py>
    Require all granted
</Files>
</Directory>

ErrorLog /var/www/logs/example1.log

</VirtualHost>


<VirtualHost *:80>

ServerName www.example2.com
ServerAlias exolcorporation.com
ServerAdmin admin@example2.com

DocumentRoot "/var/www/example2"

WSGIScriptAlias / /var/www/example2/example2/wsgi.py
WSGIDaemonProcess www.example2.com python-path=/var/www/example2:/usr/local/lib/python2.7/site-packages

<Location />
WSGIProcessGroup www.example2.com
</Location>

<Directory /var/www/example2>
<Files wsgi.py>
    Require all granted
</Files>
</Directory>

ErrorLog /var/www/logs/example2.log

</VirtualHost>

try this replacing paths and domain names
in WSGIDaemonProcess use path of your virtualenv
i didn’t used virtualenv in this example
this code works fine for me on aws ubuntu

Leave a comment