Skip to content

Setting up IIS as a reverse proxy

Overview

tl;dr;

This post is all about setting up IIS(8.5) in order to be used as a reverse proxy.

Use multiple different Webservers (IIS/Apache/Tomcat) and run them on the same server and port.

Installing IIS

Just install IIS by using the add roles and feature functionality of windows server 2012

Installing apache

I currently have the problem that I own a windows 2012 virtual server, and need to run IIS and Apache on it. Installation is actually super easy, just install IIS and then Apache (I took the apache binaries for windows from apachehaus )

But if you now try to start apache, the following error will show up:

(OS 10013)An attempt was made to access a socket in a way forbidden by its access permissions.  : AH00072: make_sock: could not bind to address [::]:80

image_thumb

This happens because I'm trying to open port 80 with apache while port 80 is already used by IIS.  And the same would happen when I try to start Tomcat or any other server which tries to run on port 80.

This error can be avoided by setting the Listen Port  of apache to anything different than port 80, i.e. 8080. Problem with this solution is that any site served by apache can only be reached via port 8080 which is super uncool since a user then has to enter the port 8080 together with the domain name.

Setup IIS

In order to use IIS as a reverse proxy, the rewrite module must be installed. This can be done by downloading it from the microsoft website

image_thumb6

To get rewrite(Not only redirect) working, the application request routing must be installed as well from the microsoft website

Now the Application Request Routing must be configured in IIS manager. It's as simple as checking the Enable proxy checkbox.

image_thumb8

image_thumb10

Now a new website must be added in IIS pointing to an empty directory. In order for IIS to act properly as a proxy, this website must be bound to a host name. (For this demo and since I don't have a hostname, I just added a entry into the host file of the computer)

image_thumb4

When now connecting to this site, noting must be shown since there is no content in the configured folder.

Next step is to setup the rewrite rule.

Setup rewrite rule in IIS

Add a new Blank rule via URL rewrite

image_thumb15

image_thumb14

The rule must look like the following sample.

This is the corresponding web.config to the screenshot below:



    
        
            
                
                    
                    
                
            
        
    


image_thumb17

Done

Now it's done. Requests sent to proxytest.com:80 will be rewritten from IIS to the address from rewrite URL.

With this configuration, it's possible to run IIS, Apache, Tomcat and many other webserver at the same time on the same server under the same port.

Great thing.

Be careful using ThreadStatic in Visual Studio unit tests

Given is a ThreadStatic field which is set to empty in the static constructor, and set by a public instance method:

    public class TestClass
    {
        [ThreadStatic] 
        private static string threadStaticValue;
        static TestClass()
        {
            threadStaticValue = "";
        }
        public void SetThreadStaticValue(string value)
        {
            threadStaticValue = value;
        }
        public string GetThreadStaticValue()
        {
            return threadStaticValue;
        }
    }

Now two unit tests check whether the threadStaticValue is set correct.

    [TestClass]
    public class ThreadStaticTest
    {
        [TestMethod]
        public void WithThreadStaticValueSetTest()
        {
            Debug.WriteLine("Thread id: {0}", System.Threading.Thread.CurrentThread.ManagedThreadId);
            TestClass tc = new TestClass();
            tc.SetThreadStaticValue("foo");
            Assert.AreSame(tc.GetThreadStaticValue(), "foo");
        }
        [TestMethod]
        public void WithThreadStaticValueNotSetTest()
        {
            Debug.WriteLine("Thread id: {0}", System.Threading.Thread.CurrentThread.ManagedThreadId);
            TestClass tc = new TestClass();
            Assert.AreSame(tc.GetThreadStaticValue(), "");
        }
    }

Those tests will fail(good) or pass(bad) depending of whether the test engine will reuse the same thread.

Executed a second time, the result could be different.

Solution:

  1. Don't use ThreadStatic at all
  2. Make sure the ThreadStatic fields are initialized correctly before using them

Daydeal competition

Daydeal holds a competition where you can win the simpons lego house.

Das Simpsons-Haus aus LEGO-Steinen

This is my contribution (My first gif).

DaydealWettbewerb

Cross your fingers!

Update

Unfortunately, I did not win the first price(simpsons house), but I got a voucher for daydeal nevertheless Smile

My first windows 8 app (MySmug for windows 8)

I've created my first windows 8 app.

It's a simple image viewer for a smugmug gallery.

MySmug for windows 8 status quo

Authentication

The preferred method to authenticate to SmugMug is OAuth V2.0.

OAuth in windows 8 can be achieved straight forward with the WebAuthenticationBroker. It will do most of the work for you. The only problem is that you can’t style this control properly.

At the moment the authentication site from SmugMug doesn't fit into the WebAuthentication-Broker control. But it seems I’m not alone with this problem.

Albums list

After a successful authentication, a list of albums is shown.

Photo & Video Sharing by SmugMug

Image list

After selecting an album from the albums list, all images from this album are shown.

Image detail

After selecting an image, it is shown full screen with some information. In this view it is possible to swipe through all images.

Settings

The good

Here I’m showing a list of things which are cool when creating a windows 8 app.

Overall concept

I like the metro concepts. I like the colors, style, tiles, contracts, responsive behavior and so on. In my opinion it is the right direction even if windows 8 is not finished yet.

Cool controls

There are a lot of cool controls like the FlipView or the WebAuthenticationBroker which hide a lot of complexity.

Good templates

There are some good metro style templates like the items page or the item detail page. They im-plement a lot of cool functionality and are quite easy to use.

Visual Studio 2012

I love VS. Just give VS2012 some more colors and don't use upper case in menu text.

And I’m missing a stable resharper for VS2012.

The bad

A list of things which suck(At the moment at least) when creating a windows 8 app.

Change from Consumer Preview to Release Preview

I've started development with the consumer preview of windows 8, and this was a mistake.

After upgrading to the release preview of windows and to VS2012, my solution didn't work any-more.

They've change the whole LayoutAwarePage on which most of my sites were based.

Windows/VS2012 crashes

While developing, i had about 10 crashes where i had to do a hard reboot. Two times i even lost source code.

Missing concepts

I miss some concepts/basic functionality in metro apps.

  • Navigation concept/Application state
  • Settings dialog.
  • Others i can't remember...
  • Unfinished and missing controls

    I tried to use the ScrollViewer in order to zoom images. After a hack with the HorizontalScroll-BarVisibility it worked, but not as smooth as it should.

    Why is there no control which i can pan/zoom and which is super-smooth and behaves as it should?

    There are people which say you have to implement this all by yourself, but i don't agree.

    Why is there no settings control/concept? I've used callisto from tim heure, but this is a control which must be part of the core.

    Why is it no possible to change the size/style of a WebAuthenticationBroker?

    Image share contract

    I've implemented an image share contract. Why for gods sake did the mail client and the build in image viewer not implement the opposite of this contract?

    At the moment it's useless (I can share images only with puzzle-touch^^)

    Next steps

    I'll try to implement a video player in order to show movies, and i'm going to cleanup the existing code.

    I also hope to get the surface tablet anytime soon... :)

    cheers

    manuel