在Apache服务器上同时运行多个Django程序的方法

yipeiwu_com6年前服务器

在同一个 Apache 实例中运行多个 Django 程序是完全可能的。 当你是一个独立的 Web 开发人员并有多个不同的客户时,你可能会想这么做。

只要像下面这样使用 VirtualHost 你可以实现:

NameVirtualHost *

<VirtualHost *>
  ServerName www.example.com
  # ...
  SetEnv DJANGO_SETTINGS_MODULE mysite.settings
</VirtualHost>

<VirtualHost *>
  ServerName www2.example.com
  # ...
  SetEnv DJANGO_SETTINGS_MODULE mysite.other_settings
</VirtualHost>

如果你需要在同一个 VirtualHost 中运行两个 Django 程序,你需要特别留意一下以 确保 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 mysite_other
  </Location>
</VirtualHost>

这个 PythonInterpreter 中的值不重要,只要它们在两个 Location 块中不同。

相关文章

Linux系统中设置多版本PHP共存配合Nginx服务器使用

应用环境 LNMP的环境,当前PHP版本5.3.8,遇到一个应用需求只支持PHP 5.2.x,又希望保持现有应用还是用PHP 5.3.8。也就是说需要两个版本的PHP同时存在,供ngin...

分析python服务器拒绝服务攻击代码

复制代码 代码如下:# -*- coding: cp936 -*-from scapy.all import *from threading import Thread,activeCo...

python登录pop3邮件服务器接收邮件的方法

本文实例讲述了python登录pop3邮件服务器接收邮件的方法。分享给大家供大家参考。具体实现方法如下: import poplib, string PopServerName =...

python实现简单的TCP代理服务器

本文实例讲述了python实现简单的TCP代理服务器的方法,分享给大家供大家参考。 具体实现代码如下: # -*- coding: utf-8 -*- ''' filename:r...

python paramiko远程服务器终端操作过程解析

这篇文章主要介绍了python paramiko远程服务器终端操作过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 1.with...