还参照了:
复制wfastcgi.py文件到项目根目录
用pip装上wfastcgi模块
重要的一步来了,去python下site-package目录
执行 wfastcgi-enable 也会生成
红框中是执行wfastcgi-enable添加的。后面一个是手工添加处理程序映射来的:
勾选掉
贴一下web.config
就是映射生成的
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <handlers> <add name="FlaskFastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:Program FilesArcGISProinPythonenvsarcgispro-py3python.exe|E:site-saae-pythonwfastcgi.py" resourceType="Unspecified" /> </handlers> </system.webServer> </configuration>
在微软的页面中也提到了如何IIS 部署 flask :
https://docs.microsoft.com/en-us/visualstudio/python/configure-web-apps-for-iis-windows?view=vs-2019
照搬了stackoverflow的回答,
以上内容:
you need to install the python,wfastcgi, and flask at your server.
You can download the python from below link:
https://www.python.org/downloads/
after installing python download the wfastcgi:
pip install wfastcgi
run the command prompt as administrator and run this command.
wfastcgi-enable
run this command to enable wfastcgi.
below is my flask example:
app.py:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello from FastCGI via IIS!"
if __name__ == "__main__":
app.run()
after creating an application to run it use below command:
python app.py
now enable the cgi feature of iis:
- now open iis.
- right-click on the server name and select add site.
- enter the site name physical path and the site binding.
- after adding site select the site name and select the handler mapping feature from the middle pane.
- Click “Add Module Mapping”
- add below value:
executable path value:
C:Python37-32python.exe|C:Python37-32Libsite-packageswfastcgi.py
- Click “Request Restrictions”. Make sure “Invoke handler only if request is mapped to:” checkbox is unchecked:
- Click “Yes” here:
- now go back and again select the server name and select fast CGI setting from the middle pane.
- Double click it, then click the “…” for the Environment Variables collection to launch the EnvironmentVariables Collection Editor:
- Set the PYTHONPATH variable:
- And the WSGI_HANDLER (my Flask app is named app.py so the value is app.app — if yours is named site.py it would be site.app or similar):
- 特别注意这里的app.py --> app.app
- Click OK and browse to your site:
Note: Do not forget to assign the iusr and iis_iusrs user permission to the flask site folder and python folder.