还参照了:

复制wfastcgi.py文件到项目根目录

用pip装上wfastcgi模块

flask在 iis中部署

 

 重要的一步来了,去python下site-package目录

flask在 iis中部署

 

 flask在 iis中部署

 

 执行 wfastcgi-enable 也会生成

flask在 iis中部署

 

 flask在 iis中部署

 

 flask在 iis中部署

 

 

红框中是执行wfastcgi-enable添加的。后面一个是手工添加处理程序映射来的:

flask在 iis中部署

 

 勾选掉

flask在 iis中部署

 

 贴一下web.config

flask在 iis中部署

 

 就是映射生成的

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <add name="FlaskFastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe|E:\site-saae-python\wfastcgi.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的回答,

https://stackoverflow.com/questions/58261464/how-to-host-python-3-7-flask-application-on-windows-server

以上内容:

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()

flask在 iis中部署

after creating an application to run it use below command:

python app.py

now enable the cgi feature of iis:

flask在 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” flask在 iis中部署
  • add below value:

flask在 iis中部署

flask在 iis中部署

flask在 iis中部署

executable path value:

C:\Python37-32\python.exe|C:\Python37-32\Lib\site-packages\wfastcgi.py

  • Click “Request Restrictions”. Make sure “Invoke handler only if request is mapped to:” checkbox is unchecked:

flask在 iis中部署

  • Click “Yes” here:

flask在 iis中部署

  • now go back and again select the server name and select fast CGI setting from the middle pane.

flask在 iis中部署

  • Double click it, then click the “…” for the Environment Variables collection to launch the EnvironmentVariables Collection Editor:

flask在 iis中部署

  • Set the PYTHONPATH variable:

flask在 iis中部署

  • 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

flask在 iis中部署

  • Click OK and browse to your site:

flask在 iis中部署

Note: Do not forget to assign the iusr and iis_iusrs user permission to the flask site folder and python folder.

另外,我设置了项目文件夹权限 everyone 全部

相关文章: