"IIS 中相当于 'proxy_set_header X-Forwarded-Proto https;' 的设置是什么?"

10
这个配置在IIS中的等效配置是什么?
我在Windows服务器上运行JetBrains YouTrack,使用IIS作为终止SSL代理。当尝试登录时,会出现以下错误:
HTTP ERROR 405

Problem accessing /hub/auth/login. Reason:

    HTTP method POST is not supported by this URL
Powered by Jetty://

我的 web.config 文件看起来像这样:

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Reverse Proxy" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="(.*)" />
          <!-- Redirect all requests to non-HTTPS site. -->
          <action type="Rewrite" url="http://my.youtrack.site/{R:1}" logRewrittenUrl="true" />
        </rule>
      </rules>
    </rewrite>
    <handlers>
      <clear />
      <!-- No other handlers required. Must clear them otherwise ASP.NET might try to intercept *.svc paths etc. -->
      <add name="Rewrite" path="*" verb="*" modules="RewriteModule" resourceType="Unspecified" />
    </handlers>
  </system.webServer>
</configuration>

我正在尝试按照此来源的解决方案:https://confluence.jetbrains.com/display/YTD65/Linux.+JAR+in+Nginx+Web+Server,但是针对的是IIS。

2个回答

17

在找到https://confluence.jetbrains.com/display/YTD65/Configuring+Proxy#ConfiguringProxy-IISreverseproxy后得到解决。

<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Reverse Proxy" patternSyntax="ECMAScript" stopProcessing="true">
                    <match url="(.*)" />
                    <!-- Redirect all requests to non-HTTPS site. -->
                    <action type="Rewrite" url="http://my.youtrack.site/{R:1}" logRewrittenUrl="true" />
                    <serverVariables>
                        <set name="HTTP_X_FORWARDED_HOST" value="{HTTP_HOST}" />
                        <set name="HTTP_X_FORWARDED_SCHEMA" value="https" />
                        <set name="HTTP_X_FORWARDED_PROTO" value="https" />
                    </serverVariables>
                </rule>
            </rules>
            <allowedServerVariables>
                <add name="HTTP_X_FORWARDED_HOST" />
                <add name="HTTP_X_FORWARDED_SCHEMA" />
                <add name="HTTP_X_FORWARDED_PROTO" />
            </allowedServerVariables>
        </rewrite>
        <handlers>
            <clear />
            <!-- No other handlers required. Must clear them otherwise ASP.NET might try to intercept *.svc paths etc. -->
            <add name="Rewrite" path="*" verb="*" modules="RewriteModule" resourceType="Unspecified" />
        </handlers>
    </system.webServer>
</configuration>

0
我能够使用以下脚本将X-Forwarded-Proto头添加到由应用程序请求路由转发的所有请求中:
Set-WebConfiguration -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.webServer/rewrite/allowedServerVariables" -Value (@{name="HTTP_X_FORWARDED_PROTO"})
Set-WebConfiguration -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.webServer/rewrite/globalRules" -value @{name='ForwardedHttps'}
Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.webServer/rewrite/globalRules/rule[@name='ForwardedHttps']/serverVariables" -name "." -value @{name='HTTP_X_FORWARDED_PROTO';value='https'}
Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.webServer/rewrite/globalRules/rule[@name='ForwardedHttps']/conditions" -name "." -value @{input='{HTTPS}';pattern='On'}

为了使代码正确处理HTTP/HTTPS重定向,可能还需要设置以下配置设置:
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST'  -filter "system.webServer/proxy" -name "preserveHostHeader" -value "True"
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST'  -filter "system.webServer/proxy" -name "reverseRewriteHostInResponseHeaders" -value "False"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接