1、pip install flask, wfastcgi
启用:到Scripts/目录下输入命令wfastcgi-enable
运行成功后会提示一下文字:"c:\program files\anaconda3\python.exe"|"c:\program files\anaconda3\lib\site-packages\wfastcgi.py"这段文字非常重要,后续在配置程序映射的时候会用到。
2、IIS安装CGI

3、安装URL Rewrite 2.0
Web Platform Installer : The Official Microsoft IIS Site
URL Rewrite : The Official Microsoft IIS Site
4、IIS 添加网站

应用程序池对应的“进程模型-> 标识”选择LocalSystem


5、配置编辑器,对system.webServer/handlers节进行解锁

6、配置webconfig文件
在Flask程序的同级目录下新建web.config文件,文件内容如下,WSGI_HANDLER配置成主程序文件的名字,后缀是app。而handlers中的FlaskFastCGI中scriptProcessor需替换成wfastcgi-enable 命令执行结果中的对应内容
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
? ? <appSettings>
? ? ? ? <add key="WSGI_HANDLER" value="app.app" />
? ? ? ? <add key="PYTHONPATH" value="~/" />
? ? </appSettings>
? ? <system.webServer>
? ? ? ? <handlers>
? ? ? ? ? ? <add name="FlaskFastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="c:\users\administrator\appdata\local\programs\python\python38\python.exe|c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages\wfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
? ? ? ? </handlers>
? ? </system.webServer>
</configuration>
7、(可选)配置web目录IIS权限
cd C:\Web
icacls . /grant "NT AUTHORITY\IUSR:(OI)(CI)(RX)"
icacls . /grant "Builtin\IIS_IUSRS:(OI)(CI)(RX)"
8、完成,浏览器输入localhost可看到Flask程序执行结果
|