在运行django应用程序的同一windows 10服务器上托管多个子域

在运行django应用程序的同一windows 10服务器上托管多个子域,django,windows,apache,web-deployment,mod-wsgi,Django,Windows,Apache,Web Deployment,Mod Wsgi,我需要托管多个子域都指向同一windows10服务器的站点。不同子域的虚拟主机指向不同的WSGI文件。Venv激活添加到wsgi文件中。发生的问题是调用的第一个Django设置文件应用于所有子域 例如。 company1.example.com->/company1_wsgi.py->company1_settings.py company2.example.com->/company2\u wsgi.py->company2\u settings.py 现在,company1\u设置同时应用于

我需要托管多个子域都指向同一windows10服务器的站点。不同子域的虚拟主机指向不同的WSGI文件。Venv激活添加到wsgi文件中。发生的问题是调用的第一个Django设置文件应用于所有子域

例如。 company1.example.com->/company1_wsgi.py->company1_settings.py company2.example.com->/company2\u wsgi.py->company2\u settings.py

现在,company1\u设置同时应用于company1.example.com和company2.example.com。我看到基于子域调用了正确的WSGI文件,但由于某些原因,os.environ['DJANGO_SETTINGS_MODULE']没有基于子域动态更新,并且始终使用第一个值

wsgi文件

python_home= 'E:/app/demo/env'
activate_this = 'E:/app/demo/env/Scripts/activate_this.py'
exec(open(activate_this).read(),dict(__file__=activate_this))
import os
import sys
from django.core.wsgi import get_wsgi_application
import site
# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('E:/app/demo/env/Lib/site-packages')




# Add the app's directory to the PYTHONPATH
sys.path.append('E:/app/demo/crm')
sys.path.append('E:/app/demo/crm/appointment_scheduler')

os.environ['DJANGO_SETTINGS_MODULE'] = 'appointment_scheduler.settings.preprod'
application = get_wsgi_application()

ServerName demo.crmbaylyn.com
WSGIScriptAlias/“E:/app/demo/crm/appointment\u scheduler/wsgi\u win.py”
WSGIPassAuthorization On
WSGIScript正在重新加载
命令拒绝,允许
通融
要求所有授权
命令允许,拒绝
通融
要求所有授权
别名/static“E:/app/demo/crm/static”
要求所有授权
斯伦金安
SSLCertificateFile“C:/Apache24/conf/crmbaylyn.cert”
SSLCertificateKeyFile“C:/Apache24/conf/crmbaylyn.key”
重新启动发动机
重写cond%{HTTP:X-Forwarded-Proto}!https
重写规则/robots.txt https://%{SERVER_NAME}%{REQUEST_URI}[L,R=301]
ServerName dev.crmbaylyn.com
WSGIScriptAlias/“E:/app/dev/crm/appointment\u scheduler/wsgi\u collection/dev\u wsgi.py”
WSGIPassAuthorization On
WSGIScript正在重新加载
命令拒绝,允许
通融
要求所有授权
命令允许,拒绝
通融
要求所有授权
别名/static“E:/app/dev/crm/static”
要求所有授权
斯伦金安
SSLCertificateFile“C:/Apache24/conf/crmbaylyn.cert”
SSLCertificateKeyFile“C:/Apache24/conf/crmbaylyn.key”

这将由mod_wsgi的WSGIDaemonProcess或WSGIProcessGroup解决(那时您将有单独的
os.environ
s等),但这些功能在Windows上不可用


如果您确实需要在Windows上运行,我建议您从mod_wsgi切换到使用代理请求,例如,或运行您的应用程序的另一个HTTP/wsgi服务器。

将项目部署到IIS,然后根据需要配置到每个网站的绑定

您可以使用
django windowsauth
包,使用几个简单的命令将项目部署到IIS

将网站添加到IIS后,请在每个项目的绑定中指定不同的主机名

<VirtualHost *:443>
ServerName demo.crmbaylyn.com
WSGIScriptAlias / "E:/app/demo/crm/appointment_scheduler/wsgi_win.py"
WSGIPassAuthorization On
WSGIScriptReloading On
<Directory "E:/app/demo/crm/appointment_scheduler">
   <Files wsgi.py>
      Order deny,allow
      Allow from all
      Require all granted
   </Files>
Order allow,deny
    Allow from all
    Require all granted
</Directory>
 Alias /static "E:/app/demo/crm/static"
    <Directory "E:/app/demo/crm/static">
        Require all granted
    </Directory>

SSLEngine on
SSLCertificateFile "C:/Apache24/conf/crmbaylyn.cert"
SSLCertificateKeyFile "C:/Apache24/conf/crmbaylyn.key"
</VirtualHost>
<VirtualHost *:80>
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule !/robots.txt https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]

</VirtualHost>
<VirtualHost *:443>
ServerName dev.crmbaylyn.com
WSGIScriptAlias / "E:/app/dev/crm/appointment_scheduler/wsgi_collection/dev_wsgi.py"
WSGIPassAuthorization On
WSGIScriptReloading On
<Directory "E:/app/dev/crm/appointment_scheduler">
   <Files wsgi.py>
      Order deny,allow
      Allow from all
      Require all granted
   </Files>
Order allow,deny
    Allow from all
    Require all granted
</Directory>
 Alias /static "E:/app/dev/crm/static"
    <Directory "E:/app/dev/crm/static">
        Require all granted
    </Directory>

SSLEngine on
SSLCertificateFile "C:/Apache24/conf/crmbaylyn.cert"
SSLCertificateKeyFile "C:/Apache24/conf/crmbaylyn.key"
</VirtualHost>