在mod_python下运行多个Django项目,而不使用VirtualHosts

时间:2010-10-04 21:49:35

标签: django mod-python apache-config

我在同一台机器上有两个django项目。它们使用标准的django / apache / mod_python配置进行设置,基本上是:

<Location "/mysite">
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE mysite.settings
    PythonOption django.root /mysite
    PythonDebug On
    PythonPath "['/path/to/project/parent'] + sys.path"
</Location>

其中mysite因两个项目而异(在Location指令中,DJANGO_SETTINGS_MODULE和django.root)。 PythonPath也各不相同。

当两个Location指令中只有一个到位时,无论哪个站点都可以正常工作。这两种配置都可以单独使用。

当我有两个Location指令(引用不同的url路径)时,我只能访问一个站点。我有“/ portal”和“/ apitest”的位置指令,当我转到http://mydomain.com/apitest时,我总是从“/ portal”获取代码。

是否可以通过包含多个Location指令来为同一主机中的两个django站点提供服务,还是需要使用VirtualHosts?

谢谢, 大卫

1 个答案:

答案 0 :(得分:2)

文档似乎暗示您可能需要为每个位置块设置不同的PythonInterpreter值。这样可以解决问题吗?

  

如果您需要在同一个VirtualHost中放置两个Django安装(或者在共享相同服务器名称的不同VirtualHost块中),您需要采取特殊的预防措施以确保mod_python的缓存不会搞砸。使用PythonInterpreter指令为不同的<Location>指令提供单独的解释器:

<VirtualHost *>
    ServerName www.example.com
    # ...
    <Location "/something">
        SetEnv DJANGO_SETTINGS_MODULE mysite.settings
        PythonInterpreter mysite
    </Location>

    <Location "/otherthing">
        SetEnv DJANGO_SETTINGS_MODULE mysite.other_settings
        PythonInterpreter othersite
    </Location>
</VirtualHost>

http://docs.djangoproject.com/en/dev/howto/deployment/modpython/#multiple-django-installations-on-the-same-apacheBlockquoteBlockquotedirectives