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

如何在Docker中通过PowerShell配置IIS的自定义CGI脚本映射?

在Docker中通过PowerShell配置IIS自定义DLL脚本映射

前置要求

  • Dockerfile基于Windows Server Core + IIS镜像(例如mcr.microsoft.com/windows/servercore/iis:windowsservercore-ltsc2019)
  • 已将自定义处理程序DLL复制到容器内的指定路径(示例:C:\inetpub\wwwroot\MyApp\bin\MyCustomHandler.dll)

配置步骤

1. 创建目标站点(若未创建)

如果容器内还没有Web-MyApp站点,先执行以下PowerShell命令创建:

New-WebSite -Name "Web-MyApp" -PhysicalPath "C:\inetpub\wwwroot\MyApp" -Port 80

2. 添加脚本映射

针对Web-MyApp站点,为.cgi扩展名绑定自定义DLL处理程序:

# 配置参数
$siteName = "Web-MyApp"
$extension = ".cgi"
$dllPath = "C:\inetpub\wwwroot\MyApp\bin\MyCustomHandler.dll"
$handlerName = "MyCustomCGIHandler"

# 添加脚本映射配置
Add-WebConfigurationProperty -Filter "/system.webServer/handlers" `
  -Name "." `
  -Value @{
    name = $handlerName;
    path = "*$extension";
    verb = "*";
    modules = "IsapiModule";
    scriptProcessor = $dllPath;
    resourceType = "Unspecified";
    requireAccess = "Script"
  } `
  -PSPath "IIS:\Sites\$siteName"

3. 启用ISAPI相关组件

确保IIS的ISAPI扩展和筛选器功能已启用,否则自定义DLL无法被加载:

Enable-WindowsOptionalFeature -Online -FeatureName IIS-ISAPIExtensions, IIS-ISAPIFilter

4. 验证配置

执行以下命令确认脚本映射是否添加成功:

Get-WebConfiguration "/system.webServer/handlers" -PSPath "IIS:\Sites\$siteName" | Where-Object { $_.name -eq $handlerName }

404错误排查要点

  • 核对容器内DLL路径与脚本映射配置中的路径完全一致,确认DLL已正确复制到容器
  • 检查站点物理路径是否指向C:\inetpub\wwwroot\MyApp,确保MyCustomCGI.cgi(或对应虚拟路径)存在
  • 查看容器内IIS日志(路径:C:\inetpub\logs\LogFiles\W3SVC*),获取具体错误细节
  • 确认ISAPI扩展功能已正常启用,无权限限制

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.09 10:35:25