10

What is the IIS equivalent of this configuration in NGINX?

proxy_set_header X-Forwarded-Proto https;

I am running JetBrains YouTrack on Windows server, using IIS as a terminating SSL proxy, and get this error when trying to log in:

HTTP ERROR 405

Problem accessing /hub/auth/login. Reason:

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

My web.config looks like this:

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

I am trying to follow the solution from this source: https://confluence.jetbrains.com/display/YTD65/Linux.+JAR+in+Nginx+Web+Server, but for IIS

invertigo
  • 6,336
  • 5
  • 39
  • 64

2 Answers2

17

Resolved after finding 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>
Littm
  • 4,923
  • 4
  • 30
  • 38
invertigo
  • 6,336
  • 5
  • 39
  • 64
0

I was able to add X-Forwarded-Proto header to all requests forwarded by Application Request Routing using the following script:

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'}

In order to make code handle HTTP/HTTPS redirects correctly the following configuration settings may need to be set as well:

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"
Smok3r
  • 71
  • 1
  • 4