IIS has been supporting reverse proxy configuration since URL Rewrite and Application Request Routing modules were released a few years ago. It is possible to configure an IIS hosted web site to act as a reverse proxy and forward web request to other URL’s based on the incoming request URL path. This is described in details in Reverse Proxy with URL Rewrite v2 and Application Request Routing.

Not too many people know however that the same kind of configuration can be achieved with a web site hosted in Azure Web Sites. This blog post explains the configurations steps to enable that.

For example if I want to forward all the requests that come to http://ruslany.net/proxy/ to some other URL I’ll need to do two things:

Enable proxy functionality in ARR

Add a proxy rewrite rule

Any site hosted in Azure Web Sites has URL Rewrite and ARR enabled. However the proxy functionality is disabled by default in ARR. To enable that we will use the Azure Site Extension XDT transform which will modify the applicationHost.config file for our site and will enable proxy features.

For the purposes of this example I configured proxy to forward all requests to http://www.iis.net/ but you can replace it with the target url of your site. Now if I browse to http://ruslany.net/proxy/ the url rewrite rule will rewrite the request to a different url and then ARR will forward the request (notice the URL in the browser window. It is still my domain name which confirms that this not an HTTP redirect).

This functionality enables some interesting use cases. For example I could have two separate azure web sites ruslany-forum.azurewebsites.net and ruslany-blog.azurewebsites.net that can appear as if they are under same hostname but in different subfolders, e.g. http://ruslany.net/blog/ and http://ruslany.net/forum/.

Update:

Thanks to Bill Harts who discovered one additional important configuration step that is required if your site also uses ASP.NET MVC. When MVC is enabled on the web site used as a proxy then the MVC Router intercepts all the requests so they are not processed by ARR. So instead of request being forwarded to a destination server you get HTTP 404 – File Not Found error.

In order to fix this you’ll need to exclude the proxy route from the MVC routes by adding the following code to you MVC application:

40 Responses to “Using Azure Web Site as a reverse proxy”

Wow, this is super helpful.
Before your post, there’s NO any official post mention about ARR on azure. Cannot believe it. Without ARR , even in memory cache will hit its bottleneck for session id sync and lookup. Now we feel easy to build up new website on Azure!

Thanks for writing this. I’m not able to get it working yet. Questions:

1. You wrote, “Next add the following rewrite rule:” but you didn’t say which file to add it to, is it web.config or applicationHost.xdt? And what directory it should be in?

2. Is there some way to debug the rules? I’m seeing a cryptic error message in the eventlog.xml file (see below) but it doesn’t really tell me much. Can I enable more detailed logging on Azure that will tell me if the rules are being matched?

Yes, the rule should be added to web.config file. As with regards to mode detailed logging – the best way to check how the rewrite rules were applied is to enable Failed Request Tracing for the web site.

I have followed your instructions exactly, adding the http://www.iis.net rewrite rule to my web.config and enabling via applicationHost.xdt. When I submit an URL with /proxy on it, the URL Rewrite logic detects it, rewrites it correctly to http://www.iis.net, but when the ApplicationRequestRouting module runs it gives an ARR_WEBFARM_NOT_ROUTED message and changes the URL back to the original /proxy. This then leads to a NOT FOUND error. I have attached the ferb log below as well as my web.config.

You can use http://www.pinproxy.com
It is the best online proxy found i have listed some features of it to help you.
They have no ads.(this is why i like them)
Supports almost every website.
Best support for youtube,facebook,myspace and much more.
They are on seperate private servers.not in a shared host so youget the best performance.
and the best part is youcan use what ever of the subdomain and access there proxy.
example: you can access the proxy from *.domain.com replace * with whatever word you like.

1. My web app is on abc.azurewebsites.net
2. API I am consuming is on xyz.com:1234/api
3. I want to make my web app IE8 compatible
4. But to avoid CORS. I want to implement something like Reverse Proxy so that all the requests made to my API will be through Proxy..

Thanks for contributing the guide “Using Azure Web Site as a reverse proxy”. I’m enjoy reading your guide for quite a while. Recently I have implemented Azure Website to act as a reverse proxy for our web servers in test environment.

I believe the xdt transform was successful based on the log file below.

Thanks for the writeup! I was able to get my site working with this guide.

If I wanted to add caching ability to my reverse proxy, how would one go about setting that up? E.g., I want the reverse proxy to honor the cache headers of the thing it is proxying and just serve up the content from its cache rather than hitting the underlying site.

Thanks for the writeup. I’m trying to redirect a page on Azure, and I get the following error:

You do not have permission to view this directory or page.

My situation is that I have a URL, we’ll call it me.com that is a utility URL. In subdirectories, there are many unique applications. But the home URL has no purpose. I’d like to redirect it to the company web page….let’s call that mycompany.com.

All I have in the site folder is the .xdt file in your write up.
All I have in the wwwroot folder is a web.config that is included in your write up.

Hi Ruslan,
I followed all the steps correctly, for testing purpose my target URL is google.com, the redirect is happening but the URL in the browser also is changing to to google.com which I think should not be happening as you also have pointed in the article, please advise what is wrong

Is this documentation still applicable now ? I created a new Webapp and copy the applicationHost.xdt in the dite folder and created a new web.config file with the content listed here and uploaded it in the wwwroot folder but all I get when brownsing to my app URL is the content of the hostingstart.html file. Should I have had other files is that wwwroot folder ?

Thanks for letting me know about that. This is most likely because iis.net site has recently added a rule on their site to enforce HTTPS. For example if you browse directly to http://www.iis.net/ you will see that you get HTTP 303 that redirects to httpS://www.iis.net/

Looks like I’ll need to update the article to point my proxy address to some other location that does not enforce https.

Hi Ruslany,
I am simply trying to Redirect HTTP requests that come in to my website to be sent to the HTTPS version. I am going through an Azure Application Gateway and have tried everything for just a basic website and can’t seem to get this working. I do not have a DNS name for my domain. This is just for testing, so I’m using this in my redirect string under URL Rewrite. https://{HTTP_HOST}{REQUEST_URI}. Any help would be much appreciated.
Steve

My redirect is working, but the website isn’t coming up.
If I type in http://server ip (no DNS setup yet), then it gets redirected to https://server ip
But I’m worried those URL Rewrite codes are not valid for server ip addresses when it says HTTP_HOST. What is my alternative for testing?

Man i want to thank you sooo much for this article !!!
I tried for 2 days to play with Azure application gateway to realize that it does not do URL rewrite.
With your solution i fixed my issue in 10 minutes.
Thanks again !

Hi Tom, thanks for reporting this. You are right, the http://www.iis.net has started to enforce https on all its URLs. I’ll need to find some other site to proxy requests too because I cannot use HTTPS with my custom domain ruslany.net as I haven’t renewed my SSL certificate

Hi @ruslany,
After reading your post I started to implement this for bringing a blog site back to company-main-domain/blog, but I got stuck trying to re-compress the content after overwrite all links from the backed site.
I was able to set the compression in my local environment(IIS 10) following other of your posts but for

(I hit return accidentally)… IIS.
Any thought? Is compression supported in azure for reverse proxy sites? Any specific work around like the ones you suggested here: https://forums.iis.net/post/1937454.aspx but for azure?
Thanks in advance.