小编Dev*_*x93的帖子

在 DSC 脚本中添加入站重写规则不起作用

正如标题所示,我正在使用以下命令配置反向代理功能的重写规则:

  • IIS 8.5
  • Windows Server 2012R2
  • URL重写2.1
  • 应用程序请求路由3.0
  • Powershell 5.1

为此,我使用 Powershell DSC,在脚本资源中设置配置。这对于出站规则非常有效,但不会创建入站规则,也不会给出错误/警告。当尝试在其上设置属性时(在后面的 3 行),确实会显示一条警告,指出它找不到入站规则,顺便说一句,还显示了正确使用的变量名称)。在 IIS 管理控制台中它也是不可见的(是的,我已经使用了 F5)。

我使用的是 IIS 本身生成的命令,它与我在网上看到的所有命令相同,包括 StackOverflow。这个特殊问题不容易找到,所以我一定错过了一些非常微不足道的东西。我已经尝试过:

  • 在不同的凭据下运行脚本
  • 使用硬编码名称而不是变量
  • 使用 URL 重写 2.0
  • 重新启动 IIS
  • 重新启动服务器

我让命令工作的唯一方法是在(提升的)Powershell(下面用 >>>> 标记)中将其作为单个命令执行。

然后是脚本本身。(作为参考,还添加了一条出站规则):

SetScript = {
            Write-Verbose "Checking if inbound rewrite rule is present..."

            $inbound = (Get-WebConfiguration -Filter "//System.webServer/rewrite/rules" -PSPath "IIS:\Sites\$using:frontendSiteName").Collection | Where-Object {$_.Name -eq "$using:inboundRuleName"}

            if($inbound -eq $null) {
                Write-Verbose "Inbound rewrite rule not present, configuring..."

        >>>>    Add-WebConfigurationProperty -Filter "//System.webServer/rewrite/rules" -Name "." -Value @{name=$using:inboundRuleName;stopProcessing="True"} -PSPath "IIS:\Sites\$using:frontendSiteName"
                Set-WebConfigurationProperty …
Run Code Online (Sandbox Code Playgroud)

iis powershell url-rewrite-module dsc

5
推荐指数
1
解决办法
1448
查看次数

标签 统计

dsc ×1

iis ×1

powershell ×1

url-rewrite-module ×1