I need to host multiple sites with subdomains all pointing to the same windows10 server. virtual hosts for different sub-domains points to different WSGI files. Venv activation is added in wsgi file. The issue happening is first Django settings file which is invoked is applied to all sub-domains.
eg.
company1.example.com -> /company1_wsgi.py -> company1_settings.py
company2.example.com -> /company2_wsgi.py -> company2_settings.py
Now, company1_settings is applied for both company1.example.com and company2.example.com. I see right WSGI files are called based on the sub-domain but for some reason os.environ[‘DJANGO_SETTINGS_MODULE’] is not being updated dynamically based on the subdomains and always uses the first value
wsgi file
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>
2
Answers
This would be solved by mod_wsgi’s WSGIDaemonProcess or WSGIProcessGroup (as then you’d have separate
os.environ
s and so on), but those features are not available on Windows.If you really need to run on Windows, I would suggest switching away from mod_wsgi to using a regular reverse proxy configuration to proxy requests to e.g. Waitress or another HTTP/WSGI server running your app.
Deploy your projects to IIS, then configure the binding to each WebSite as you need.
You can use the
django-windowsauth
package to deploy your project to IIS using few simple commands. https://github.com/danyi1212/django-windowsauth.After adding the websites to IIS, specify your different host names in the bindings of each project.