IIS URL 重寫:@import in section?

IIS URL 重寫:@import in section?

我嘗試將 JetBrains TeamCity(在連接埠 81 上使用 TomCat)置於 IIS 7 後面,以便http://www.example.com/teamcity/被代理到http://我的伺服器:81/。我想我已經大部分工作了,除了 TeamCity 在<style>元素中輸出 @import 之外。我不知道如何定義出站規則來處理這個問題。

如何讓 URL 重寫來處理這個問題?

或者,我可以教 TeamCity 有關替代虛擬目錄的信息,以便它為所有內容添加前綴/teamcity嗎?

或者,是否有更好的方法將 TeamCity 置於 IIS 7.5 後面?

答案1

更新:以下內容並非完全有效:某些 Javascript 有問題,且登出重定向已損壞。

選項:

  1. 在正在偵聽的 Tomcat 安裝中託管 TeamCity /teamcity;那就不需要出站規則了。我已經在 drupal 安裝中使用了它。
  2. 而是重定向teamcity.example.com(無虛擬目錄)。有範例步驟別處。這將需要一些 DNS CNAME 和通配符憑證(如果使用 HTTPS 進行外部存取)。

我將把其他說明留給後代......

您可以透過設定 來配置 URL 重寫來重寫文字的任何部分filterByTags="None"

所以我現在有以下內容C:\Inetpub\wwwroot\web.config

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <!-- Anything to http://www.example.com/teamcity/ should be
             rewritten to http://teamcity:81/ -->
        <rule name="TeamCity (/teamcity)">
          <match url="^teamcity/(.*)" />
          <serverVariables>
            <!-- URL Rewrite can't deal with Encoding: gzip; turn that off. -->
            <set name="HTTP_ACCEPT_ENCODING" value="" />
          </serverVariables>
          <action type="Rewrite"
                  url="http://teamcity:81/{R:1}" />
        </rule>
      </rules>

這就是入站規則;出站規則有3條:

      <outboundRules>

登入重定向:

        <!-- 302 Redirects (for the login page, e.g.) need to be rewritten. -->
        <rule name="Teamcity (/teamcity) - Redirect" preCondition="IsRedirect">
          <match serverVariable="RESPONSE_LOCATION"
                 pattern="http://[^/]+/(.*)" />
          <action type="Rewrite"
                  value="http://www.example.com/teamcity/{R:1}" />
        </rule>

正常的 HTML 重寫:

        <!-- Links in HTML need to be rewritten. -->
        <rule name="TeamCity (/teamcity) - HTML" preCondition="IsHTML">
          <!-- I've ellided the other tag types here; you might want them. -->
          <match filterByTags="A, ..."
                 pattern="^(.*)" />
          <action type="Rewrite"
                  value="http://www.example.com/teamcity/{R:1}" />
        </rule>

@import CSS 檔案:

        <!-- TeamCity uses @import for styles; fix that. -->
        <rule name="TeamCity (/teamcity) - Style" preCondition="IsHTML">
          <match filterByTags="None" pattern="@import &quot;/" />
          <action type="Rewrite" value="@import &quot;/teamcity/" />
        </rule>

還有一些前提條件:

        <preConditions>
          <preCondition name="IsRedirect">
            <add input="{RESPONSE_STATUS}" pattern="302" />
          </preCondition>
          <preCondition name="IsHTML">
            <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
          </preCondition>
        </preConditions>
      </outboundRules>

    </rewrite>
  </system.webServer>
</configuration>

它似乎有效,但如果我發現其他任何內容,我會回來更新這個答案。

相關內容