【问题标题】:IIS Equivalent of "proxy_set_header X-Forwarded-Proto https;"IIS 等效于“proxy_set_header X-Forwarded-Proto https;”
【发布时间】:2016-01-08 15:43:20
【问题描述】:

在 NGINX 中这种配置的 IIS 等效项是什么?

proxy_set_header X-Forwarded-Proto https;

我在 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

【问题讨论】:

    标签: iis nginx youtrack


    【解决方案1】:

    找到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>
    

    【讨论】:

      【解决方案2】:

      我能够使用以下脚本将 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"
      

      【讨论】:

        猜你喜欢
        • 2014-01-11
        • 2014-06-14
        • 2019-01-26
        • 2013-01-04
        • 1970-01-01
        • 2016-11-11
        • 2016-03-30
        相关资源
        最近更新 更多