1

I am trying to setup two django websites on a windows server platform with Apache. I am able to run both sites individually via apache successfully. But now running them together via virtual hosts seems to be tricky.

Here is my attempt on configuration of both httpd file and wsgi files-

Apache httpd config -

 LoadFile "c:/python/python39.dll"
LoadModule wsgi_module "c:/python/lib/site-packages/mod_wsgi/server/mod_wsgi.cp39-win_amd64.pyd"
WSGIPythonHome "c:/python"

#Virtual host for first site
<VirtualHost *:80>
WSGIScriptAlias / "C:/doctormainfolder/doctorwebsite/doctorwebsite/wsgi.py"
ServerName doctor.com

<Directory "C:/doctormainfolder/doctorwebsite/doctorwebsite/">
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>

Alias /static "C:/doctormainfolder/doctorwebsite/static/"
<Directory "C:/doctormainfolder/doctorwebsite/static/">
    Require all granted
</Directory>
ScriptInterpreterSource Registry
</VirtualHost>



#Virtual host for second site
<VirtualHost *:80>
WSGIScriptAlias / “C:/betamainfolder/betawebsite/betawebsite/wsgi.py"
ServerName beta.com

<Directory "C:/betamainfolder/betawebsite/betawebsite/">
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>

Alias /static “C:/betamainfolder/betawebsite/static/"
<Directory “C:/betamainfolder/betawebsite/static/">
    Require all granted
</Directory>
ScriptInterpreterSource Registry
</VirtualHost>

Here are wsgi file details for first website

import os
import os
import sys
path = 'C:/doctormainfolder/doctorwebsite'
if path not in sys.path:
    sys.path.append(path)

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'doctorwebsite.settings')

application = get_wsgi_application()


Here are wsgi files details for second website -

import os
import sys
path = 'C:/betamainfolder/betawebsite'
if path not in sys.path:
    sys.path.append(path)

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'betawebsite.settings')

application = get_wsgi_application()

UPDATE

I read the link and here are the updates to config. What I am observing is that whichever virtualhost is listed first, loads the site normally. The virtual host second in sequence does not load. From apache error log I could see that in this case, doctorwebsite fails to load with the error -

"ModuleNotFoundError: No module named 'betawebsite'\r", which is kind of confusing as to why doctorwebsite would search for a module in betawebsite.

VIRTUAL HOST SETTINGS

<VirtualHost *:80>
ServerName beta.com
WSGIScriptAlias / "C:/betamainfolder/betawebsite/betawebsite/wsgi.py" application-group=site2


<Directory "C:/betamainfolder/betawebsite/betawebsite/">
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>

Alias /static "C:/betamainfolder/betawebsite/static/"
<Directory "C:/betamainfolder/betawebsite/static/">
    Require all granted
</Directory>
ScriptInterpreterSource Registry
</VirtualHost>

<VirtualHost *:80>
ServerName doctor.com
WSGIScriptAlias / "C:/doctormainfolder/doctorwebsite/doctorwebsite/wsgi.py" application-group=site1


<Directory "C:/doctormainfolder/doctorwebsite/doctorwebsite/">
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>

Alias /static "C:/doctormainfolder/doctorwebsite/static/"
<Directory "C:/doctormainfolder/doctorwebsite/static/">
    Require all granted
</Directory>
ScriptInterpreterSource Registry
</VirtualHost>

Here is the WSGI from both -

import os
import sys

from django.core.wsgi import get_wsgi_application
sys.path.append('C:/betamainfolder/betawebsite')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'betawebsite.settings')

application = get_wsgi_application()

import os
import sys
from django.core.wsgi import get_wsgi_application
sys.path.append('C:/doctormainfolder/doctorwebsite')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'doctorwebsite.settings')

application = get_wsgi_application()

RKs
  • 173
  • 1
  • 1
  • 10
  • See my answer here as a start: https://stackoverflow.com/questions/64907416/how-should-i-add-wsgipython-path-in-virtualhost-for-windows-server – Razenstein Dec 31 '20 at 18:09
  • @Razenstein, I have made the changes as per the link. But I what find is that whichever virtual host is listed first, gets loaded. The second virtual host fails to load. Details in the update... thank you for taking out the time to help me out... – RKs Dec 31 '20 at 19:45
  • Just 2 ideas: first Apache is always using the first virtserver in the file if he cant resolve the server name correctly. So for develpment I would define a first virthost with only an index.html with a short message so that you realize if it is a name problem. Second my virt hosts are always defined in httpd-vhosts.conf. I am not sure if Apache can correctly treat them from httpd.conf – Razenstein Jan 01 '21 at 12:07
  • after few days struggling with windows, I moved over the project to centos. Not saying that getting the project to work on centos was easy but it got the job done... – RKs Jan 06 '21 at 06:32

0 Answers0