You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求指导:Windows IIS部署Masonite框架Python Web应用

Windows IIS部署Masonite Python Web应用指南

前置准备

  • 确认Windows服务器已安装IIS,且启用CGI、FastCGI组件(通过服务器管理器的「添加角色和功能」完成)
  • 安装Python 3.8及以上稳定版本,安装时勾选「Add Python to PATH」
  • 执行命令pip install wfastcgi安装FastCGI适配工具

配置FastCGI映射

  1. 打开IIS管理器,右键服务器名称,选择「FastCGI设置」
  2. 点击右侧「添加应用程序」,填写以下信息:
    • 可执行文件:选择Python安装目录下的python.exe(示例路径:C:\Python39\python.exe)
    • 参数:填写wfastcgi.py的完整路径(可通过pip show wfastcgi查看安装位置,一般在Python目录的Lib\site-packages\wfastcgi.py)
  3. 保存配置

部署Masonite应用

  1. 将Masonite项目文件上传至IIS站点目录(示例路径:C:\inetpub\wwwroot\masonite-app)
  2. 在项目根目录创建web.config文件,内容如下(注意替换路径为你的实际路径):
<configuration>
  <system.webServer>
    <handlers>
      <add name="Python FastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:\Python39\python.exe|C:\Python39\Lib\site-packages\wfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
    </handlers>
    <rewrite>
      <rules>
        <rule name="Masonite Routes" stopProcessing="true">
          <match url="^(.*)$" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="wsgi.py" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
  <appSettings>
    <add key="WSGI_HANDLER" value="masonite.wsgi.application" />
    <add key="PYTHONPATH" value="C:\inetpub\wwwroot\masonite-app" />
  </appSettings>
</configuration>
  1. 配置Masonite环境:
    • 在项目根目录创建.env文件,设置APP_URL为站点域名/IP,生产环境下将APP_DEBUG设为false
    • 执行python craft optimize生成优化后的配置文件

权限配置

  • 右键IIS中的Masonite站点,选择「编辑权限」,为IIS_IUSRS用户分配项目目录的读取、执行权限
  • 确保Python安装目录及site-packages目录也给IIS_IUSRS用户读取权限

测试部署

启动IIS站点,访问站点域名或IP,验证应用是否正常加载。若出现错误,可通过IIS的「日志」和「失败请求跟踪」功能排查问题

内容的提问来源于stack exchange,提问作者Chia Chet Shian

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 01:05:55