如何为多个单独的Django实例配置Apache WSGI?

时间:2013-07-26 13:39:20

标签: python django apache2 mod-wsgi

我有一个apache实例,我有以下

WSGIPythonPath /production/somelocation/django12/lib/python2.4/site-packages/
<VirtualHost 192.168.1.1:443>
        WSGIScriptAlias / /opt/project.wsgi
        .....

我的Django 1.5 app apache配置看起来像,

WSGIPythonPath /production/somelocation/django15/lib/python2.7/site-packages/
<VirtualHost 192.168.1.2:443>
        ....
        WSGIScriptAlias / /opt/project2.wsgi

我的/opt/project.wsgi看起来像

import os
import sys

# django1.2 virtualenv
import site
site.addsitedir("/production/somelocation/django12/lib/python2.4/site-packages")
.....

然而,当我去网站时,我仍然得到我的默认django(1.5)实例。我错过了什么?

4 个答案:

答案 0 :(得分:8)

其他答案提到设置python路径,但是使用WSGIPythonPath或WSGIPythonHome是不正确的。 WSGIPythonPath / WSGIPythonHome只能设置为服务器范围,因此每个虚拟主机没有不同的路径。

您可能希望使用WSGIDaemonProcess python-path home 参数来设置每个虚拟主机的python路径和应用主目录。

此外,在您的代码中,不需要调整python路径;只需确保您的虚拟主机配置正确。

答案 1 :(得分:1)

您可能需要设置WSGIPythonHome,因为您有不同的Django安装。

WSGIPythonPath用于定义其他目录,但此选项不设置 default python安装。所以可能,你的默认python目录还包括 django(1.5),并将此版本识别为默认的django版本。我不知道你的python和django安装和配置,但这可能是原因。

WSGIPythonHome

的其他信息

答案 2 :(得分:1)

这就是我对金字塔的处理方式:

<VirtualHost *:80>
    Servername hackintosh
    DocumentRoot "/Library/WebServer/Documents"
</VirtualHost>


<VirtualHost *:80>
    ServerName modwebsocket.local
    ErrorLog "/PythonProjects/MOD_WEBSOCKET/logs/error_log"
    CustomLog "/PythonProjects/MOD_WEBSOCKET/logs/access_log" common

    WSGIDaemonProcess pyramid-modwebsocket user=apero group=staff threads=4 python-path=/PythonProjects/MOD_WEBSOCKET/lib/python2.7/site-packages
    WSGIProcessGroup pyramid-modwebsocket

    WSGIScriptAlias /  /PythonProjects/MOD_WEBSOCKET/wsgi/pyramid.wsgi

    <Directory "/PythonProjects/MOD_WEBSOCKET/wsgi">
        WSGIProcessGroup pyramid-modwebsocket
        Order allow,deny
        Allow from all
    </Directory>

</VirtualHost>

<VirtualHost *:80>
    ServerName ai.local
    ErrorLog "/PythonProjects/AI/logs/error_log"
    CustomLog "/PythonProjects/AI/logs/access_log" common

    WSGIApplicationGroup %{GLOBAL}
    WSGIPassAuthorization On
    WSGIDaemonProcess pyramid-ai user=apero group=staff threads=4 python-path=/PythonProjects/AI/lib/python2.7/site-packages
    WSGIProcessGroup pyramid-wizard

    WSGIScriptAlias /  /PythonProjects/AI/wsgi/pyramid.wsgi

    <Directory "/PythonProjects/AI/wsgi">
        WSGIProcessGroup pyramid-ai
        Order allow,deny
        Allow from all
    </Directory>

</VirtualHost>

答案 3 :(得分:1)

本主题及典型原因详述如下:

您的问题中没有足够的信息来正确评估您遇到的问题。