在apache上的不同virtualenv中运行多个django项目
我想在不同的virtualenv中运行两个不同的django_项目。 代码如下:在apache上的不同virtualenv中运行多个django项目,django,apache,virtualhost,Django,Apache,Virtualhost,我想在不同的virtualenv中运行两个不同的django_项目。 代码如下: 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
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
ServerName ubuntu\u server\u apache
ServerName dev.hexxie.com
ErrorLog“/home/ashish/deployments/mysite\u dev/conf/mysite\u dev\u error.log”
WSGIScriptAlias//home/ashish/deployments/mysite\u dev/mysite/mysite/wsgi.py
别名/static/home/ashish/deployments/mysite\u dev/static\u root
要求所有授权
别名/media/home/ashish/deployments/mysite\u prod/data/media
要求所有授权
要求所有授权
WSGIPythonPath/home/ashish/deployments/mysite\u dev/mysite:/home/ashish/.virtualenvs/mysite\u dev/lib/python2.7/site-packages
服务器名hexxie.com
ServerAlias*.hexxie.com
ErrorLog“/home/ashish/deployments/mysite\u prod/conf/mysite\u error.log”
WSGIScriptAlias//home/ashish/deployments/mysite\u prod/mysite/mysite/wsgi.py
别名/static/home/ashish/deployments/mysite\u prod/static\u root
要求所有授权
别名/media/home/ashish/deployments/mysite\u prod/data/media
要求所有授权
要求所有授权
WSGIPythonPath/home/ashish/deployments/mysite\u prod/mysite:/home/ashish/.virtualenvs/mysite\u prod/lib/python2.7/site-packages
但是我使用这个apache配置文件时遇到了内部服务器错误。我觉得这是由于在配置文件中使用了两次WSGIPythonPath造成的。
WSGIPythonPath
不能包含在virtualhost中。那么,如何在apache上的diff virtualenv上分别运行两个diff django项目呢?下面是一个示例。当然,您必须根据设置更改路径/项目名称(例如端口443上的SSL,但也适用于端口80):
LoadModule wsgi\u module modules/mod\u wsgi.so
LoadModule ssl\u module modules/mod\u ssl.so
WSGISocketPrefix/var/run/wsgi
名称虚拟主机*:443
听我说
ServerName your.server.com
ErrorLog/home/user/apache_errors.log
wsgidaemonprocessproject1 https python home=/home/user/.virtualenvs/project1
WSGIScriptAlias/project1/var/www/html/project1/project1/wsgi.py进程组=project1 https应用程序组=project1 https
WSGIProcessGroup项目1 https
别名/project1/static//var/www/html/project1/static/
wsgidaemonprocessproject2 https python home=/home/user/.virtualenvs/project2
WSGIScriptAlias/project2/var/www/html/project2/project2/wsgi.py进程组=project2 https应用程序组=project2 https
WSGIProcessGroup项目2 https
别名/project2/static//var/www/html/project2/static/
以这种方式配置时,virtualenv负责Python可执行文件和路径。首先,使用守护进程组,使每个进程在单独的进程中运行,然后在相应的
WSGIDaemonProcess
组指令上使用Python home
选项。见:
WSGIDaemonProcess
选项来WSGIDaemonProcess时,不需要您的WSGIProcessGroup
指令。后一个WSGIProcessGroup
实际上无论如何都会覆盖第一个,并且不会做您期望的事情。您还应该将应用程序组
选项设置为%{GLOBAL}
,前提是该流程组中只有该应用程序。这避免了Python的某些第三方C扩展模块的问题。还要注意,如果您有80/443,则不需要为443使用单独的流程组。可以引用早期端口80中的一个VirtualHost
。哇,直接从马嘴里!感谢您参与其中,因此,在mod_wsgi上拥有源代码权威确实是非常有益的。非常感谢!谢谢@Graham!这有帮助
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>