2

I am trying to add WSGIPythonPath in VirtualHost but it's throwing me an error:

Syntax error on line 549 of /etc/httpd/conf/httpd.conf:

WSGIPythonPath cannot occur within section

I tried to resolve it by following: Where should WSGIPythonPath point in my virtualenv?

But, on researching more, I found that WSGIDaemonProcess and WSGIProcessGroup are not supported on Windows according to Why WSGIDaemonProcess isn't available on Windows?.

So, How should I add WSGIPythonPath and where so that I can host multiple Django site on my Apache24 server.

Any help would be beneficial.

Here is my httpd.conf file:

LoadFile "c:/python37/python37.dll"
LoadModule wsgi_module "c:/python37/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win_amd64.pyd"
WSGIPythonHome "c:/python37"
WSGIPythonPath "E:/edukon/"
Listen 7020

<VirtualHost *:7020>
ServerName 000.000.000.000

# Django Project

WSGIScriptAlias / "E:/edukon/edukon/wsgi.py"


<Directory "E:/edukon/edukon">
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>

Alias /static "E:/edukon/static/"
<Directory "E:/edukon/static/">
    Require all granted
</Directory>

Alias /media "E:/edukon/media/"
<Directory "E:/edukon/media/">
    Require all granted
</Directory>
</VirtualHost>

1 Answers1

1

I had a difficult journey setting up two virt. hosts with Apache mod_wsgi under Windows. So the solution here is for Apache/mod_wsgi and Windows.

In general I find it quite difficult to seperate Apache/mod_wsgi for windows and unix as in many articles the two are mixed or it is not clearly mentioned at all which one is being talked about.

  1. Here is the important part of virt host definition in httpd-vhosts.conf because in Apache/mod_wsgi for Windows you have no WSGIDaemonProcess/WSGIProcessGroup availible.
   <VirtualHost *:80>
            ServerName name1
            WSGIScriptAlias / "D:/....../wsgi.py" application-group=site1
            ......                                                                            
     </VirtualHost>
 
    <VirtualHost *:80>
            ServerName name2
            WSGIScriptAlias / "D:/....../wsgi.py" application-group=site2
            ......                                                                            
     </VirtualHost>

If you do not add "application-group..." only the virtual host that is first called after Apache restart will initialize with wsgi.py and settings.py and afterwards will get all requests to virt. hosts that have a WSGIScriptAlias or in other words that are handled by mod_wsgi!! To my understanding this is a rather serious bug because a virt host should always get his own "thread" as standard behavior of Apache/mod_wsgi. Btw Site1 and Site2 are just names that must be different.

  1. The WSGIPythonPath can not be assigned inside the virt. Hosts section. You need to put the equivalent path assignment in the wsgi.py file of each of your apps:
    sys.path.append('D:/........../xxxxx_project/xxxxx')
    os.environ['DJANGO_SETTINGS_MODULE'] = 'xxxxx.settings'
    application = get_wsgi_application()
Razenstein
  • 3,532
  • 2
  • 5
  • 17