问题描述
我的Django应用程序部署遇到问题。我遵循了一些教程(最后一个是https://www.youtube.com/watch?v=APCQ15YqqQ0)来帮助我部署应用程序,但我不明白为什么我的Handler无法正常工作。这是我的web.config文件:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="Python FastCGI"
path="*"
verb="*"
modules="FastCgiModule"
scriptProcessor="c:\users\xxx\documents\github\app_folder\scripts\python.exe|c:\users\xxx\documents\github\app_folder\lib\site-packages\wfastcgi.py"
resourceType="Unspecified"
requireAccess="Script" />
</handlers>
</system.webServer>
<appSettings>
<add key="PYTHONPATH" value="C:\Users\xxx\Documents\GitHub\app_folder\app" />
<add key="WSGI_HANDLER" value="app_name.wsgi.application" />
<add key="DJANGO_SETTINGS_MODULE" value="app_name.settings" />
</appSettings>
</configuration>
在app_folder
文件夹中有virtualenv时,app
文件夹中包含Django项目。
我有此消息要输出:
Additional information about the error :
Module FastCgiModule
Notification ExecuteRequestHandler
Handler django_handler_test
Error code 0x8007010b
URL requested http://localhost:94/
Physical Path C:\Users\xxx\Documents\GitHub\app_folder\app
Session opening Method Anonyme
User Session Anonyme
我用法语翻译了类别名称
即使不是一个好的做法,我也打算暂时在Windows计算机上部署它,然后再在服务器(Windows或Linux)上进行完整部署。现在,我确实需要在Windows环境下完成测试。感谢您的帮助和理解。
解决方法
首先,请确保您使用的是高于3.6的python版本。另一个不需要的是为所有用户安装python并将驱动器下的安装文件夹设置为“ C:\ Python36”
在Windows上安装Django:
可以使用PIP通过pip install django
从用户目录中将应用程序文件夹获取到c驱动器。
启用iis cgi功能:
使用以下命令安装wfastcgi:
pip install wfastcgi
配置IIS以运行FastCGI应用程序:
1)在iis中选择您的站点。
2)打开Handler映射配置功能。
3)在其中,单击“添加模块映射...”操作,然后输入以下信息:
<system.webServer>
<handlers>
<add name="PythonHandler" path="*" verb="*" modules="FastCgiModule"
scriptProcessor="C:\Python37-32\python.exe|C:\Python37-32\Lib\site-packages\wfastcgi.py"
resourceType="Unspecified" requireAccess="Script"/>
</handlers>
</system.webServer>
4)下一步,单击“请求限制”按钮,然后编辑“映射”选项卡。取消选中“仅在请求映射到…时才调用处理程序”复选框(否则,IIS在映射它认为是URL请求中的子目录时会遇到问题):
在处理程序信息对话框中单击确定。然后,IIS将要求您确认是否需要创建匹配的FastCGI应用程序条目。
在IIS中配置FastCGI:
1)打开iis,然后双击“ FastCGI设置”图标
2)选择您的python可执行文件并添加以下环境变量:
名称:PYTHONPATH 值:C:appsfoo
名称:WSGI_HANDLER 值:django.core.wsgi.get_wsgi_application()
名称:DJANGO_SETTINGS_MODULE 值:django_iis_example.settings
注意:不要忘记为python和site文件夹分配iis_iusrs和iusr权限。
https://docs.microsoft.com/en-us/visualstudio/python/configure-web-apps-for-iis-windows?view=vs-2019