用HttpPlatformHandler替代wfastcgi,在IIS上部署python web应用

补充:请注意,以下这个配置并不适合用在生产环境,因为它启动的是开发环境的简易服务器,要用在生产环境还是需要配合HttpPlatformHandler + waitress (因为Gunicorn 和 uwsgi 不支持windows)

arguments="manage.py runserver %HTTP_PLATFORM_PORT%"

微软官方提示建议使用 HttpPlatform 配置应用,因为他们不再维护 WFastCGI 项目 了。

首先下载并安装HttpPlatformHandler  https://www.iis.net/downloads/microsoft/httpplatformhandler

然后直接把以下web.config复制保存到网站根目录

<?xml version="1.0" encoding="UTF-8"?>  
<configuration>  
 <system.webServer>

  <handlers>
    <add name="httpPlatformHandler" path="*" verb="*"
               modules="httpPlatformHandler" resourceType="Unspecified"/>
  </handlers>

  <httpPlatform processPath="D:\http\asp\www_mysite\venv\Scripts\python.exe" arguments="manage.py runserver %HTTP_PLATFORM_PORT%" requestTimeout="00:04:00" startupTimeLimit="120" startupRetryCount="3" stdoutLogEnabled="true">
    <environmentVariables>
     <environmentVariable name="PYTHONPATH" value="D:\http\asp\www_mysite\mysite"/>
    </environmentVariables>
  </httpPlatform>

 </system.webServer>
</configuration>  

就这么简单,不需要wfastcgi那些enable什么的设置了

具体参考:

对于Django来说,可以直接参考https://azureossd.github.io/2017/09/01/django-app-with-httpplatformhandler-in-azure-app-services-windows/

 更通用则参考官方指引:

《为 Python Web 应用配置 IIS》:

https://learn.microsoft.com/zh-cn/visualstudio/python/configure-web-apps-for-iis-windows?view=vs-2022

 《HttpPlatformHandler 配置参考》:

https://learn.microsoft.com/zh-cn/iis/extensions/httpplatformhandler/httpplatformhandler-configuration-reference

  • 10
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值