python - 如何在单个 apache 服务上设置多个 django 版本?

标签 python django apache

我使用的是 Windows XP,想知道如何通过虚拟主机在单个 apache 服务上创建多个 django 版本(当然)。

我也尝试用一个 python 实例来做到这一点。我应该为每个 django 版本创建 1 个 python 实例,还是 django 只需要它的 Egg 即可工作,这样我就可以在一个 Python 版本中拥有多个 Egg?

最佳答案

您可以在 httpd.conf 中执行类似的操作

NameVirtualHost 0.0.0.0:80
<VirtualHost 0.0.0.0:80>
    ServerName myserver.com
    ServerAdmin myemail@gmail.com
    DocumentRoot "/path/to/html/root"
    ErrorLog "/path/to/apache-error.log"
    CustomLog "/path/to/apache-access.log" common

    Options ExecCGI FollowSymLinks MultiViews

    AddHandler wsgi-script .wsgi
    WSGIDaemonProcess djangoapp1
    WSGIProcessGroup djangoapp1
    WSGIScriptAlias / /path/to/djangoapp1.wsgi

    Alias /static /path/to/static/files

    DirectoryIndex index.html index.cgi

    AddHandler cgi-script .cgi .pl
</VirtualHost>

NameVirtualHost 0.0.0.0:81
<VirtualHost 0.0.0.0:81>
    ServerName myserver.com
    ServerAdmin myemail@gmail.com
    DocumentRoot "/path/to/html/root"
    ErrorLog "/path/to/apache-error.log"
    CustomLog "/path/to/apache-access.log" common

    Options ExecCGI FollowSymLinks MultiViews

    AddHandler wsgi-script .wsgi
    WSGIDaemonProcess djangoapp2
    WSGIProcessGroup djangoapp2
    WSGIScriptAlias / /path/to/djangoapp2.wsgi

    Alias /static /path/to/static/files

    DirectoryIndex index.html index.cgi

    AddHandler cgi-script .cgi .pl
</VirtualHost>

然后,在 djangoapp1.wsgi/djangoapp2.wsgi 脚本中,您可以定义不同的 django 版本和应用程序:

#!/usr/bin/python
import os
import sys
sys.path.append('')
sys.path.append('/path/to/python2.7/site-packages')
sys.path.append('/path/to/python2.7/dist-packages/Django-1.3-py2.7.egg ')
... etc ...
sys.path.append('/path/to/djangoapp1/src')
os.environ['DJANGO_SETTINGS_MODULE'] = 'djangoapp1.settings'
os.environ['PYTHON_EGG_CACHE'] = '/tmp'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

关于python - 如何在单个 apache 服务上设置多个 django 版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7614940/

相关文章:

Python/Django : How to remove extra white spaces & tabs from a string?

python - Ceph radosgw - 存储桶策略 - 默认使所有对象公开读取

python - 如何动态更改 __slots__ 属性?

Django 休息注册

django - 使用 Django-graphos 显示图表

apache - 在 apache 上的 modsecurity 中通过 ID 禁用规则

wordpress - Chrome 版本 44.0.2403.xx 的 HTTPS header 问题

php - 停止向浏览器打印 php 错误消息

python - 将带有反斜杠后跟数字的字符串转换为路径

c++ - 用于访问 BeagleBone Black 的库(3.8 Kerne - Angstrom)