user3607128 user3607128 - 1 month ago 17
Apache Configuration Question

multiple Django projects apache virtual hosts

I'm a newbie to apache.
So I'm trying to run at least two different django projects on one Ubuntu Server with a single IP address.


  • IP: 123.456.789

  • Domain 1: www.example.de for Project1

  • Domain 2:
    www.test.de for Proejct2



The DNS for both domains is pointing on the same IP Address.
I'm using apache2 with mod_wsgi in Daemon mode.
Each Project has its own directory in ~/.
I've also installed a virtaulenv with python inside the Project directorys

The problem is that no matter how I configurate the apache2.conf, both domains point to Project1.
What is weird is that they even do when it when I comment all the custom settings in apache2.conf.
Can someone please explain this?

here is my apache2.conf

Listen 80
<VirtualHost *:80>
ServerName www.example.de
WSGIScriptAlias / /home/user/example/example-project/wsgi.py
Alias /static/ /home/user/example/static/
WSGIPythonPath /home/user/example
<Directory /home/user/example/static>
Require all granted
</Directory>
<Directory /home/user/example/example>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess example.de python-path=/home/user/example:/home/user/example/exampleenv/lib/python2.7/site-packages
WSGIProcessGroup example.de
</VirtualHost>

Listen 8080
<VirtualHost *:80>
Servername www.test.de
WSGIScriptAlias / /home/user/test/test-project/wsgi.py
Alias /static/ /home/user/test/static/
<Directory /home/user/test/static>
Require all granted
</Directory>
<Directory /home/user/test/test-project>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess test.de python-path=/home/user/test:/home/user/test/testenv/lib/python2.7/site-packages
WSGIProcessGroup test.de
</VirtualHost>


Even if there is something wrong with my config, why does it still run when i comment everything in this blog? Where else is apache getting the information from?

Answer

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.

Comments