Access VisualSVN Server and TeamCity through IIS7

by Terry Hughes Sunday, October 11, 2009 11:20 AM

I run IIS, VisualSVN Server, and TeamCity on the same machine and everything works great, except for one small thing: they all need their own port to listen too. I ended up with IIS on 80, VisualSVN Server on 81, and TeamCity on 82. Yuck! The URLs look horrible and you have to remember to explicitly prefix the non 80 ports with http://. What I really want is for everything to be on port 80.

Googling the interwebs, I learned that what I wanted to do was have IIS be a reverse proxy for VisualSVN Server and TeamCity. I also learned that there is an extension, Application Request Routing, for IIS7 that does this very thing. I found an article that outlined how to do what I wanted, but there are a couple of special things that need to be done to get VisualSVN Server and TeamCity working.

Application Request Routing
I enabled the proxy, which is explained in the Configuring Rules for the Reverse Proxy section of the previous link, and took this opportunity to add a rewrite rule to the Default Web Site that will prefix www to any request that does not have it, the rule configuration can be found a little over halfway through the video on the URL Rewrite Module page. As an aside, after adding the rule, Google Reader showed that existing postings where new entries. I think this is because I had FeedBurner pointing to tnthughes.net/blog not www.tnthughes.net/blog. I'm not sure if there would have been a way to prevent the duplication of posts since the URLs are technically different.

TeamCity
At first I tried to proxy TeamCity from a subdirectory, but it returns link references to items at the root URL and I was unsuccessful at correctly rewriting the links. Since I run other applications within the same web site, I couldn't have TeamCity use www.tnthughes.net directly, so I decided to add a TeamCity subdomain in my DNS settings. I updated my prefix www rule to have a second condition so it didn't try to change TeamCity.tnthughes.net to www.tnthughes.net. I then added a rewrite rule to the Default Web Site that matches any url with the condition that the HTTP_POST is TeamCity.tnthughes.net to rewrite to http://localhost:82/{R:1}.

VisualSVN Server
Since TeamCity had it's own domain I wanted to do the same thing for VisualSVN Server, only it didn't work. Remember how VisualSVN Server will automatically append svn/ when you type in just the root address? There is a reason for this, I'm not sure what the reason is, but it is how VisualSVN Server works. So VisualSVN Server has to be proxied at a subdirectory. At first I set the rewrite rules to use a nonexistant directory but found out that IIS blocks files that have certain extensions. Some of the blocked extensions are the very same as the file extensions that I want VisalSVN Server to serve. In order to work around that and not expose those file types in other applications that are running in the same web site, I opted to have a physical directory so I can override the default IIS settings. I created a new folder called svn within the wwwroot folder on my server. I then added a rewrite rule to the svn folder that matches any url to rewrite to http://localhost:81/svn/{R:1}. I couldn't find a way in the UI to change the file extensions that IIS served but this post shows the xml configuration syntax needed to tell IIS that it's okay to serve certain extensions. I updated the web.config in the svn directory to allow for the extensions .config, .cs, and .csproj. This isn't all inclusive, just want I've ran across so far. Then i noticed something. If I typed in tnthughes.net/svn the links went to tnthughes.net/{Repository} and would give a 404 error if clicked. Realizing that the ending slash was needed, I played around a bit and figured out that by adding a rewrite rule to the Default Web Site that matches ^svn$ to redirect to http://www.tnthughes.net/svn/ I could always ensure that there was an ending slash. The other thing with VisualSVN Server is that it expects it's images and styling files to be at the root of the URL. So I had to copy the files under %ProgramFiles%\VisualSVN Server\htdocs\ (minus index.html) to the wwwroot folder.

The order in which the rules are processed matters. If the rule for TeamCity happened after the rule to append the ending slash for VisualSVN Server, TeamCity.tnthughes.net/svn would take me to www.tnthughes.net/svn/, not exactly what I wanted.

A side benefit to all of this is that now I can close the non 80 ports on my router and disable the firewall rules on the server. So now I have what I wanted. It's not exactly perfect, I'd must prefer TeamCity to be in a subdirectory like VisualSVN Server, but I can live with it. For now.

About Me

TerryH   I'm a senior software developer currently working on a foreign exchange portfolio management system for a financial company with a bunch of awesome people.

Disclaimer

The opinions and viewpoints expressed on this blog are not necessarily those of a cultured, tactful, or well-balanced person. This blog is a product of me, who is solely responsible for its content. Me - Stealing From Smart Developers.

Copyright © 2008-2011 Terry Hughes. All rights reserved.