python flask 发布于IIS

预备:

  • 假定IIS已经安装
  • 安装 Python
             1. 安装web版 ( Python 3.7.0).

                 2. 按管理员权限运行

                 3. 自定义安装,并适用于所有人

                 4. 自定义文件夹 "D:\python\python3.7"

                 5. 添加到系统路径.

                              PATH = D:\Python\Python37;D:\Python\Python37\Scripts

  • 安装Wfastcgi,并是能.
    1. 管理员权限打开命令终端
    2. 运行: pip install wfastcgi
      如上指令安装 wfastcgi. 该包在 IIS 和 Python之间使用 WSGI 和 FastCGI建立桥梁
    3. 终端中继续执行: wfastcgi-enable

                              该命令将会产生相关信息如下:

                              """

                              Applied configuration changes to section "system.webserver/fastcgi" for "MACHINE/WEBROOT/APPHOST" at configuration commit path "MACHINE/WEBROOT/APPHOST".

                              " D:\python\python37\python.exe| D:\python\python37\lib\site-packages\wfastcgi.py" can now be used as a FastCGI script processor.                             

                              Below tag is created in the app host config.

<fastCgi>

<application fullPath="D:\python\python37\python.exe" arguments="D:\python\python37\lib\site-packages\wfastcgi.py" signalBeforeTerminateSeconds="30" />

</fastCgi>

                              """

该步骤执行结果配置可以放在web.config中。

设置 Website
==================

  • IIS中添加Website
  • 添加必要信息 (此处端口设为 8001).
  • 物理路径为网页所在位置及web.config和myapp.py (Web.config and myapp.py):
  • web.config: 包含web配置,如下内容(注意红色字体必须为app): 

<configuration>

  <system.webServer>

    <handlers>

      <add name="Python FastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="D:\Python\Python37\python.exe|D:\Python\Python37\Lib\site-packages\wfastcgi.py" resourceType="Unspecified" requireAccess="Script" />

    </handlers>

  </system.webServer>

  <appSettings>

    <!-- Required settings -->

    <add key="WSGI_HANDLER" value="myapp.app" />

    <add key="PYTHONPATH" value="D:\inetpub\wwwroot\MyPython" />

  </appSettings>

</configuration>

  • myapp.py: contains Flask application                             

from flask import Flask

app = Flask(__name__)

@app.route('/')

def hello():

    return "Hello welcome to the website!"

if __name__ == '__main__':

    app.run()

IIS安装好CGI后在FastCGI 设置中设置好Handler Mappings.

Under FastCGI settings, I have the following:

  1. Under Handler Mappings, you'll see different names. Based on web.config, you'll see "Python FastCGI".

                

  • NOTE : 应用程序池设置 (D:\Python\Python37) for the to user “IIS AppPool\MyPython” .

              

测试时发现web重启不能立刻更新内容,需要在应用程序线程池里点击回收才能立刻更新。

参考

https://segmentfault.com/a/1190000008909201

windows IIS部署python Flask网站_david_lee13的博客-CSDN博客_flask iis部署

https://techcommunity.microsoft.com/gxcuf89792/attachments/gxcuf89792/IIS-Support-Blog/318/1/How%20to%20run%20Python%20Application%20on%20IIS%20that%20uses%20Flask%20Framework%20and%20Wfastcgi.docx

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值