大赵传奇

援引事类,扬搉古今,举要删芜,言辩而理切--QQ276605216

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

还参照了:

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

enter image description here

after creating an application to run it use below command:

python app.py

now enable the cgi feature of iis:

enter image description here

  • 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” enter image description here
  • add below value:

enter image description here

enter image description here

enter image description here

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:

enter image description here

  • Click “Yes” here:

enter image description here

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

enter image description here

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

enter image description here

  • Set the PYTHONPATH variable:

enter image description here

  • 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

enter image description here

  • Click OK and browse to your site:

enter image description here

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

另外,我设置了项目文件夹权限 everyone 全部
posted on 2021-03-31 14:43  赵长青  阅读(823)  评论(0编辑  收藏  举报