正如标题所示,我正在使用以下命令配置反向代理功能的重写规则:
为此,我使用 Powershell DSC,在脚本资源中设置配置。这对于出站规则非常有效,但不会创建入站规则,也不会给出错误/警告。当尝试在其上设置属性时(在后面的 3 行),确实会显示一条警告,指出它找不到入站规则,顺便说一句,还显示了正确使用的变量名称)。在 IIS 管理控制台中它也是不可见的(是的,我已经使用了 F5)。
我使用的是 IIS 本身生成的命令,它与我在网上看到的所有命令相同,包括 StackOverflow。这个特殊问题不容易找到,所以我一定错过了一些非常微不足道的东西。我已经尝试过:
我让命令工作的唯一方法是在(提升的)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)