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

如何使用IIS部署Strapi应用?配置web.config遇iisnode错误

IIS部署Strapi解决iisnode错误指南

先确认基础依赖是否到位

  • 得确保IIS上装了URL Rewrite和iisnode模块,版本要和你用的Node.js适配(iisnode对Node版本有兼容性要求,优先选LTS版本)
  • 服务器上的Node.js得是全局可用的,打开命令行敲node -v能正常返回版本号才算没问题

替换成Strapi专用的web.config配置

普通Node项目的web.config适配不了Strapi,因为Strapi有自己的路由逻辑和启动入口。下面是能用的配置:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="iisnode" path="server.js" verb="*" modules="iisnode" />
    </handlers>
    <rewrite>
      <rules>
        <rule name="Strapi 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="server.js" />
        </rule>
      </rules>
    </rewrite>
    <iisnode 
      nodeProcessCommandLine="&quot;C:\Program Files\nodejs\node.exe&quot;" 
      loggingEnabled="true"
      logDirectory="iisnode"
      debuggingEnabled="true"
      debugHeaderEnabled="true"
    />
    <security>
      <requestFiltering>
        <hiddenSegments>
          <remove segment="node_modules" />
        </hiddenSegments>
      </requestFiltering>
    </security>
  </system.webServer>
</configuration>

注意点:

  • 把nodeProcessCommandLine里的路径改成你服务器上Node.js的实际安装路径
  • Strapi默认启动文件是server.js,如果是Strapi v4+,先确认项目根目录有这个文件;如果没有,去看package.json里start脚本指向的入口文件是什么,把配置里的path改成对应文件名

一步步排查错误

  1. 看iisnode日志:配置里开了loggingEnabled="true",项目根目录会生成iisnode文件夹,里面的日志会写清楚具体错在哪(比如端口被占、依赖没装、环境变量不对)
  2. 检查Strapi环境变量:服务器上得设对NODE_ENV(生产环境设成production),还有数据库连接字符串这类必要配置
  3. 先验证本地启动正常:在服务器上用命令行跑npm run start,确认Strapi能正常启动后再用IIS部署
  4. 权限要给够:给IIS应用池对应的用户分配项目目录的读写权限,尤其是uploads、build这些文件夹

常见踩坑点

  • Node.js版本不兼容:iisnode对Node 16+的支持需要特定版本,建议用Node.js 18 LTS
  • 端口冲突:Strapi默认用1337端口,先确认这个端口没被其他服务占着,或者去Strapi配置里改端口
  • 依赖没装全:服务器上项目目录里要执行npm install --production装生产依赖

内容的提问来源于stack exchange,提问作者Guilherme Bezerra

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.19 15:12:09