在几个Apache Virtualhosts上提供一个Django应用程序

时间:2017-06-12 13:03:04

标签: python django apache mod-wsgi virtualhost

我们有一个由Apache(mod-wsgi)提供的Django应用程序,具有这样的配置:

<VirtualHost vhost:80>
  # ...
  WSGIScriptAlias / /path/to/wsgi.py
</VirtualHost>

我们希望将该单个应用程序提供给2个虚拟主机:vhost:80vhost:443 ...客户端迁移所需的时间,最后只保留在https virtualhost。 是否可以将指令WSGIScriptAlias / /path/to/wsgi.py复制到第二个虚拟主机(vhost:443)中,或者我们是否会遇到使用相同数据库运行两次相同应用程序的问题?

1 个答案:

答案 0 :(得分:1)

首先,您要确保使用的是mod_wsgi的守护进程模式,而不是嵌入模式。无论哪种方式,如果使用多进程配置,您将有多个应用程序实例访问同一个数据库。这通常不是问题。在为SSL添加虚拟主机时,问题是加倍进程数。这是守护进程模式的用武之地。典型的配置是:

<VirtualHost *:80>
  ServerName sitename.example.com

  # Define a daemon process group.

  WSGIDaemonProcess sitename

  # Specify WSGI application and delegate to daemon process group.
  # As delegating here, don't need WSGIProcessGroup/WSGIApplicationGroup.

  WSGIScriptAlias / /path/to/wsgi.py process-group=sitename application-group=%{GLOBAL}

  # ... access control directives

</VirtualHost>

<VirtualHost *:443>
  ServerName sitename.example.com

  # ... SSL options

  # Specify WSGI application and delegate to daemon process group.
  # As delegating here, don't need WSGIProcessGroup/WSGIApplicationGroup.
  #
  # Note that we did not define a daemon process group in this virtual
  # host. Instead we rely on fact that can reach across and use daemon
  # process group defined in virtual host for port 80. This is possible
  # as value of ServerName is the same.

  WSGIScriptAlias / /path/to/wsgi.py process-group=sitename application-group=%{GLOBAL}

  # ... access control directives

</VirtualHost>

如果需要调整容量和性能,请将process=nnnthreads=nnn选项添加到WSGIDaemonProcess。还要确保修改可能要在守护程序进程组上设置的超时选项。