如何在Windows Server的VirtualHost中添加WSGIPython路径? [英] How should I add WSGIPython path in VirtualHost for Windows server?
问题描述
我正在尝试在 VirtualHost
中添加 WSGIPythonPath
,但这会引发一个错误:
I am trying to add WSGIPythonPath
in VirtualHost
but it's throwing me an error:
/etc/httpd/conf/httpd.conf的第549行的语法错误:
Syntax error on line 549 of /etc/httpd/conf/httpd.conf:
WSGIPythonPath不能在该部分内出现
WSGIPythonPath cannot occur within section
我尝试通过以下方法解决该问题:在我的virtualenv中WSGIPythonPath应该指向哪里?
I tried to resolve it by following: Where should WSGIPythonPath point in my virtualenv?
但是,在进行更多研究后,我发现Windows根据 WSGIProcessGroup
/6586412/why-wsgidaemonprocess-isnt-available-on-windows>为什么WSGIDaemonProcess在Windows上不可用?.
But, on researching more, I found that WSGIDaemonProcess
and WSGIProcessGroup
are not supported on Windows according to Why WSGIDaemonProcess isn't available on Windows?.
因此,我应该如何添加 WSGIPythonPath
以及在哪里添加,以便可以在Apache24服务器上托管多个Django站点.
So, How should I add WSGIPythonPath
and where so that I can host multiple Django site on my Apache24 server.
任何帮助都是有益的.
这是我的 httpd.conf
文件:
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>
推荐答案
我艰难地建立了两种形式.Windows下使用Apache mod_wsgi托管主机.因此,这里的解决方案是针对Apache/mod_wsgi和Windows的.
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.
总的来说,我发现很难将Apache/mod_wsgi用于Windows和Unix,因为在许多文章中两者是混合使用的,或者根本没有提到谈论哪一个.
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.
- 这是httpd-vhosts.conf中virt主机定义的重要部分,因为在Windows的Apache/mod_wsgi中,没有WSGIDaemonProcess/WSGIProcessGroup可用.
<VirtualHost *:80>
ServerName name1
WSGIScriptAlias / "D:/....../wsgi.py" application-group=site1
......
</VirtualHost>
<VirtualHost *:80>
ServerName name2
WSGIScriptAlias / "D:/....../wsgi.py" application-group=site2
......
</VirtualHost>
如果您不添加"application-group ...",只有在Apache重新启动后首先调用的虚拟主机才会使用wsgi.py和settings.py初始化,然后将所有请求发送到virt.具有WSGIScriptAlias或换句话说由mod_wsgi处理的主机!据我了解,这是一个相当严重的错误,因为病毒宿主应该始终获得自己的线程"线程.作为Apache/mod_wsgi的标准行为.顺便说一句,Site1和Site2只是必须不同的名称.
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.
- 不能在virt中分配WSGIPythonPath.主机部分.您需要将等效的路径分配放入每个应用程序的wsgi.py文件中:
sys.path.append('D:/........../xxxxx_project/xxxxx')
os.environ['DJANGO_SETTINGS_MODULE'] = 'xxxxx.settings'
application = get_wsgi_application()
这篇关于如何在Windows Server的VirtualHost中添加WSGIPython路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!