Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm attempting to put JetBrains TeamCity (which uses TomCat on port 81) behind IIS 7, so that http://www.example.com/teamcity/ is proxied to http://myserver:81/. I think I've got it mostly working, except that TeamCity outputs @import in the <style> element. I can't figure out how to define an outbound rule to deal with this.

How do I get URL rewrite to deal with this?

Or, alternatively, can I teach TeamCity about the alternative virtual directory, so that it prefixes everything with /teamcity?

Or, more alternatively, is there a better way to put TeamCity behind IIS 7.5?

share|improve this question

1 Answer 1

Update: The following doesn't completely work: some of the Javascript is problematic, and the logout redirect is broken.

Options:

  1. Host TeamCity in a Tomcat installation that's listening to /teamcity; then there'll be no need for outbound rules. I've got this working for a drupal installation.
  2. Redirect teamcity.example.com instead (no virtual directory). There are example steps for this elsewhere. This will require some DNS CNAMEs and a wildcard certificate (if using HTTPS for external access).

I'll leave the other instructions here for posterity...

You can configure URL Rewrite to rewrite any part of the text, by setting filterByTags="None".

So I now have the following in 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>

That's the inbound rule; there are three outbound rules:

      <outboundRules>

Login redirects:

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

Normal HTML rewriting:

        <!-- 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 of CSS files:

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

And some pre-conditions:

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

It appears to work, but I'll come back and update this answer if I find anything else.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.