Run multiple django projects in different virtualenv on apache

I want to run two different django_projects each in different virtualenv. This is the code:

ServerName ubuntu_server_apache <VirtualHost *:80> ServerName dev.hexxie.com ErrorLog "/home/ashish/deployments/mysite_dev/conf/mysite_dev_error.log" WSGIScriptAlias / /home/ashish/deployments/mysite_dev/mysite/mysite/wsgi.py Alias /static /home/ashish/deployments/mysite_dev/static_root <Directory /home/ashish/deployments/mysite_dev/static_root> Require all granted </Directory> Alias /media /home/ashish/deployments/mysite_prod/data/media <Directory /home/ashish/deployments/mysite_prod/data/media> Require all granted </Directory> <Directory /home/ashish/deployments/mysite_dev/mysite/mysite> <Files wsgi.py> Require all granted </Files> </Directory> </VirtualHost> WSGIPythonPath /home/ashish/deployments/mysite_dev/mysite:/home/ashish/.virtualenvs/mysite_dev/lib/python2.7/site-packages <VirtualHost *:80> ServerName hexxie.com ServerAlias *.hexxie.com ErrorLog "/home/ashish/deployments/mysite_prod/conf/mysite_error.log" WSGIScriptAlias / /home/ashish/deployments/mysite_prod/mysite/mysite/wsgi.py Alias /static /home/ashish/deployments/mysite_prod/static_root <Directory /home/ashish/deployments/mysite_prod/static_root> Require all granted </Directory> Alias /media /home/ashish/deployments/mysite_prod/data/media <Directory /home/ashish/deployments/mysite_prod/data/media> Require all granted </Directory> <Directory /home/ashish/deployments/mysite_prod/mysite/mysite> <Files wsgi.py> Require all granted </Files> </Directory> </VirtualHost> WSGIPythonPath /home/ashish/deployments/mysite_prod/mysite:/home/ashish/.virtualenvs/mysite_prod/lib/python2.7/site-packages 

But I get an internal server error using this apache conf. I feel this is due to the fact that WSGIPythonPath is used twice in conf. WSGIPythonPath cannot be included inside a virtual host. So how to run two django diff projects each on diff virtualenv on apache?

+5
source share
2 answers

First, use the daemon process group, so each one runs in a separate process, and then use the python-home option in the corresponding WSGIDaemonProcess group WSGIDaemonProcess . Cm:

+3
source

Here is an example of how I do it. Naturally, you will have to change the paths / names of the projects based on your installation (for example, SSL on port 443, but it also works on port 80):

 LoadModule wsgi_module modules/mod_wsgi.so LoadModule ssl_module modules/mod_ssl.so WSGISocketPrefix /var/run/wsgi NameVirtualHost *:443 Listen 443 <VirtualHost *:443> ServerName your.server.com ErrorLog /home/user/apache_errors.log WSGIDaemonProcess project1-https python-home=/home/user/.virtualenvs/project1 WSGIScriptAlias /project1 /var/www/html/project1/project1/wsgi.py process-group=project1-https application-group=project1-https WSGIProcessGroup project1-https Alias /project1/static/ /var/www/html/project1/static/ WSGIDaemonProcess project2-https python-home=/home/user/.virtualenvs/project2 WSGIScriptAlias /project2 /var/www/html/project2/project2/wsgi.py process-group=project2-https application-group=project2-https WSGIProcessGroup project2-https Alias /project2/static/ /var/www/html/project2/static/ </VirtualHost> 

Virtualenv performs customization and the path to Python when configured in this way.

+1
source

All Articles