Iis – Reverse proxy subdomain to subfolder on IIS7

iisreverse-proxyweb-applicationsweb-server

I'm currently trying to implement an Owncloud system at our company. I have the Owncloud system up and running on an internal webserver which is behind a firewall. I can access the installation internally by navigating to servername.company.co.nz/owncloud

We have an IIS webserver that is public facing (SBS 2012). I'd like to use this as a reverse proxy to the cloud installation. I have read a few articles and tutorials on how to achieve this using URL Rewriting and ARR on IIS – this one in particular seemed like a good start : IIS 7 Reverse Proxy based on domain name host?

But so far I have not been able to create any reverse proxy rules that work.

Basically, I would like a subdomain cloud.company.co.nz to reverse proxy to the internal webserver path server.company.co.nz/owncloud have not been able to figure out how to achieve this.

I currently have a new website on out IIS server which is bound to the cloud.company.co.nz hostname, but that's about all I've been able to accomplish without knocking over our Exchange Web Services.

Please bear in mind I am an IIS newbie. Any help is greatfuly received at this stage.

Edit 1:

As per @jotap's suggestion, my web.config now looks like this. However, all I get is a 503 error. Any ideas as to why I would get this? Also, where should I be looking in terms of logs etc for clues?

Cheers

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" enabled="false" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="http://1.2.3.4/owncloud{R:1}" />
</rule>
</rules>
<outboundRules>
<rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1" enabled="false">
<match filterByTags="A, Form, Img" pattern="^http(s)?://1.2.3.4/owncloud/(.*)" />
<action type="Rewrite" value="http{R:1}://cloud.company.co.nz/{R:2}" />
</rule>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
</system.webServer>
</configuration>

Best Answer

The devil is in the detail when it comes to reverse proxying with IIS and ARR, the basic steps to achieve this are:

  • Install ARR and URLRewrite
  • Configure ARR for reverse proxying: Server level of IIS --> Application Request Routing Cache --> Server Proxy Settings
    • The most basic setup that should get you going is "Enable Proxy" and leave the rest as is.
  • Configure the site to proxy all requests to the new host. This can be done through the GUI, alternately you can use this web.config to get you going (put it in the root of the site that is doing the proxying):

    <?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="inbound"> <match url="(.*)" /> <action type="Rewrite" url="http://server.company.co.nz/owncloud/{R:0}" /> </rule> </rules> </rewrite> </system.webServer> </configuration>

Not sure if you're familiar with regular expressions, that is basically saying, "capture the URL after the host name, and make a request to server.company.co.nz, tacking the captured URL on to the end of the owncloud subdir".

Note that you may have issues if the site on the back end is compressing the content (you'll get a 500 error). In addition if it works you may find all your images and CSS are broken, in which case and you'll have to do configure outbound rewriting also, but that depends on your back end and the rules are specific to the issues you may have so see how you go. You may have to do another dozen tweaks (or more) to get it right.

Related Topic