在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 块中不同。

相关文章

python制作websocket服务器实例分享

python制作websocket服务器实例分享

一、开始的话   使用python简单的实现websocket服务器,可以在浏览器上实时显示远程服务器的日志信息。   之前做了一个web版的发布系统,但没实现在线看日志,每次发布版本后...

python下paramiko模块实现ssh连接登录Linux服务器

本文实例讲述了python下paramiko模块实现ssh连接登录Linux服务器的方法。分享给大家供大家参考。具体分析如下: python下有个paramiko模块,这个模块可以实现s...

Python实现的ftp服务器功能详解【附源码下载】

Python实现的ftp服务器功能详解【附源码下载】

本文实例讲述了Python实现的ftp服务器功能。分享给大家供大家参考,具体如下: python 具备强大的网络编程功能,而且代码简介,用简单的代码,就能实现一个功能强大的FTP 服务器...

centos+nginx+uwsgi+Django实现IP+port访问服务器

centos+nginx+uwsgi+Django实现IP+port访问服务器

环境 MacBookAir 阿里云ESC: Centos7.0 nginx+1.16.1 uwsgi=2.0.18 django=2.2.7 服务器 进入阿里云...

Python3 jupyter notebook 服务器搭建过程

1. jupyter notebook 安装 •创建 jupyter 目录 mkdir jupyter cd jupyter/ •创建独立的 Python3...