I was setting up a new instance of Team City 4.0 on our development server at Six Day Tech today and ran into an all too frequent problem with our Apache Reverse Proxy server.
I basically accepted the defaults during the Team City install which gave me a local URL of something like: http://dev:8081/ . I then set up a proxy rule in our Apache configuration to proxy http://dev.ourdomain.com/TeamCity to the http://dev:8081 address on the dev server using the following proxy settings.
(*Additional proxy settings not specific to Team City have been omitted)
These settings allowed me to get to the TeamCity login page but the style sheet and JavaScript references where all pointed to the root, e.g. /css/style.css instead of to /TeamCity/css/style.css. The login page was actually displaying a missing JavaScript error and even if I could have gotten by with the missing styles I knew this was no good.
Because we are running all our traffic through our proxy server through HTTPS and only have one IP address we couldn't use an Apache Virtual Host and a URL like https://TeamCity.ourdomain.com. So my choices where to add some sort of URL Rewrite rule to our proxy server or to get TeamCity to run from a sub directory on the host server. I chose to look at how to get TeamCity to run from a sub directory. This was consistent with some of the other sites were are running through our proxy server so I thought it would be no problem... until I discovered that TeamCity is running inside a Tomcat server.
It took me about an hour of searching the net to come up with clear instructions on how to create a virtual directory in Tomcat, called a context so I'll just cut to the chase of how I finally set it up.
- Stop the TeamCity Service
- Locate and the server.xml file in <TeamCity_Install_Dir>/conf directory. (For me that was in D:\Programs\TeamCity\conf
- Open the server.xml file in Notepad
- Find the first 'Host' section. Mine looked like this.
1: <Host name="localhost" appBase="webapps"
2: unpackWARs="true" autoDeploy="true"
3: xmlValidation="false" xmlNamespaceAware="false">
- Inside the Host section added the following Context element to create the sub directory. Where the value for 'docBase' points back to the TeamCity install directory.
1: <Context path="/TeamCity"
2: docBase="D:\Programs\TeamCity\webapps\ROOT"
3: debug="1"
4: reloadable="true" > </Context>
- Restart the TeamCity service and made sure it worked locally from http://dev:8081/TeamCity
- Updated the Apache Proxy settings to include the sub directory and restarted the Apache Proxy server.
Now I get a pretty URL to my TeamCity site and the benefits of having a secure connection without having to setup Tomcat to communicate in HTTPS.