Firstly, I'd like to thank you for maintaining this excellent utility.

I should note that I am not a technically-versed person in these matters, 
so apologies if I am slow to pick up on things.

As for my problem, I want to host multiple Django-based websites from the 
same httpd.exe process on Windows. I do not know how to go about this.

Details on my setup:
- mod_wsgi (v5.0.0)
- Python (v3.9.2)
- Apache (v2.4.58), with the binaries being distributed by ApacheLounge 
(2024-01-31 release)
- Windows Server 2012 R1 (and not R2)
- Django v4.2.10
- I am hosting two distinct domain names (e.g. "someexample.com" and 
"anotherexample.com")
- Everything is set up from scratch in the sense that I have physical 
access to the machine running the web server, access to the domain names, 
access to the router, etc.
- Because I am running Windows, I am running mod_wsgi in embedded mode. My 
installation of Apache is mostly standard, so something like mod_python is 
not installed.

Here is the relevant snippet of Apache configuration. I am aware that it 
does not run (because WSGIPythonPath cannot be in a VirtualHost directive), 
but it encapsulates the logic of what I am trying to go for:

LoadFile 
"C:/Users/Administrator/AppData/Local/Programs/Python/Python39/python39.dll"
LoadModule wsgi_module 
"C:/Users/Administrator/Desktop/SERVERS/web_server_production/python_virtual_environment/lib/site-packages/mod_wsgi/server/mod_wsgi.cp39-win_amd64.pyd"

WSGIPythonHome 
"C:/Users/Administrator/Desktop/SERVERS/web_server_production/python_virtual_environment"


# VIRTUAL HOST: "someexample.com"

<VirtualHost *:80>
ServerName someexample.com
ServerAlias www.someexample.com
Redirect permanent "/" "https://someexample.com/";
</VirtualHost>

<VirtualHost *:443>
ServerName someexample.com
ServerAlias someexample.com
<If "%{HTTP_HOST} == 'www.someexample.com'">
Redirect "/" "https://someexample.com/";
</If>

SSLEngine On
SSLCertificateFile "..."
SSLCertificateKeyFile "..."

WSGIScriptAlias / 
"C:/Users/Administrator/Desktop/SERVERS/web_server_production/website_projects/someexample.com/main/wsgi.py"
WSGIPythonPath 
"C:/Users/Administrator/Desktop/SERVERS/web_server_production/website_projects/someexample.com"

<Directory 
"C:/Users/Administrator/Desktop/SERVERS/web_server_production/website_projects/someexample.com/main">
<Files "wsgi.py">
Require all granted
</Files>
</Directory>

Alias "/assets/" 
"C:/Users/Administrator/Desktop/SERVERS/web_server_production/website_projects/someexample.com/@assets/"

<Directory 
"C:/Users/Administrator/Desktop/SERVERS/web_server_production/website_projects/someexample.com/@assets/">
Require all granted
</Directory>

</VirtualHost>


# VIRTUAL HOST: "anotherexample.com"

<VirtualHost *:80>
ServerName anotherexample.com
ServerAlias www.anotherexample.com
Redirect permanent "/" "https://anotherexample.com/";
</VirtualHost>

<VirtualHost *:443>
ServerName anotherexample.com
ServerAlias www.anotherexample.com
<If "%{HTTP_HOST} == 'www.anotherexample.com'">
Redirect "/" "https://anotherexample.com/";
</If>

SSLEngine On
SSLCertificateFile "..."
SSLCertificateKeyFile "..."

WSGIScriptAlias / 
"C:/Users/Administrator/Desktop/SERVERS/web_server_production/website_projects/anotherexample.com/main/wsgi.py"
WSGIPythonPath 
"C:/Users/Administrator/Desktop/SERVERS/web_server_production/website_projects/anotherexample.com"

<Directory 
"C:/Users/Administrator/Desktop/SERVERS/web_server_production/website_projects/anotherexample.com/main">
<Files "wsgi.py">
Require all granted
</Files>
</Directory>

Alias "/assets/" 
"C:/Users/Administrator/Desktop/SERVERS/web_server_production/website_projects/anotherexample.com/@assets/"

<Directory 
"C:/Users/Administrator/Desktop/SERVERS/web_server_production/website_projects/anotherexample.com/@assets/">
Require all granted
</Directory>

</VirtualHost>


If further information is needed, such as what my file structure for these 
website (Django) projects look like, or how wsgi.py is configured (I 
*mostly* used the default generation given by Django), I can provide those 
too.

Probably worth noting, but when starting a new project with Django, it 
usually names the "main package" as whatever the project was named (usually 
the name is just the website's name). Instead, I renamed that package to 
"main" (and it has the same name across all websites) and updated the 
appropriate references (e.g. "main.settings" inside of "wsgi.py" instead of 
"someexamplecom.settings"). This is a convention I would prefer to keep, if 
possible, though I am willing to revert to Django's default convention if 
it is truly necessary.

-- 
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/modwsgi/d2b81c58-9d22-4720-a6d3-38eec28ca9a8n%40googlegroups.com.

Reply via email to