Search code examples
pythondjangovirtualenvmod-wsgiwsgi

Serving multiple Django projects in different virtualenv at the same IP (Apache)


I'm trying to serve two Django projects on different virtualenv at the same IP adress on Apache.

My first site is at http://myip/site-1 and the seccond: http://myip/site-2

When I run http://myip/site-1, Apache serves it without issues, but when I run the second (http://myip/site-2) it raises the following:

The requested URL /site-2/ was not found on this server.

Because it searches in the first site's document root.

Here is my apache.conf

<VirtualHost *:80>
  ServerName site-1.example.com
  DocumentRoot /home/venv/site-1

 # adjust the following line to match your Python path 
 WSGIDaemonProcess site-1.example.com processes=2 threads=15 display-name=%{GROUP} python-home=/home/venv/lib/python2.7
 WSGIProcessGroup site-1.example.com
 WSGIScriptAlias / /home/venv/site-1/site-1/wsgi.py

 <directory /home/venv/site-1>
   AllowOverride all
   Require all granted
   Options FollowSymlinks
 </directory>

 Alias /static/ /home/venv/site-1/static_root/

 <Directory /home/venv/site-1/static_root>
   AllowOverride all
   Require all granted
   Options FollowSymlinks
 </Directory>

</VirtualHost>

<VirtualHost *:80>
  ServerName site-2.example.com
  DocumentRoot /home/venv_mob/site-2

  # adjust the following line to match your Python path 
  WSGIDaemonProcess site-2.example.com processes=2 threads=15 display-name=%{GROUP} python-home=/home/venv_mob/lib/python2.7
  WSGIProcessGroup site-2.example.com
  WSGIScriptAlias / /home/venv_mob/site-2/site-2/wsgi.py

<directory /home/venv_mob/site-2>
   AllowOverride all
   Require all granted
   Options FollowSymlinks
 </directory>

 Alias /static/ /home/venv_mob/site-2/static_root/

<Directory /home/venv_mob/site-2/static_root>
  AllowOverride all
  Require all granted
  Options FollowSymlinks
 </Directory>

</VirtualHost>

I have tried many solutions that I found on the web but the problem remains the same.

Any ideas ?


Solution

  • You have to connect to http://site-1.example.com (using terms from your example), not http://myip/site-1. And http://site-2.example.com, not http://myip/site-2.

    Generally speaking you can have name-based virtual hosts for which you need to configure DNS (mapping site-1.example.com and site-2.example.com to your IP address) or you can run different sites on different ports.