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

问题描述 投票:0回答:1

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

例如company1.example.com-> /company1_wsgi.py-> company1_settings.pycompany2.example.com-> /company2_wsgi.py-> company2_settings.py

现在,company1_settings应用于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()
<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>

django windows apache web-deployment mod-wsgi
1个回答
0
投票

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

如果您确实需要在Windows上运行,我建议您从mod_wsgi切换到使用a regular reverse proxy configuration将请求代理到例如Waitress或其他运行您的应用程序的HTTP / WSGI服务器。

© www.soinside.com 2019 - 2024. All rights reserved.