Using Azure Web Site as a reverse proxy

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 https://ruslany.net/proxy/ to some other URL I’ll need to do two things:

  1. Enable proxy functionality in ARR
  2. 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.

Continue reading “Using Azure Web Site as a reverse proxy”

Azure Web Sites – block web access to non-production deployment slots

Windows Azure Web Sites supports Staged Publishing functionality, which allows you to create a staging site slot where you can publish a new version of the website and then test it before swapping to the production environment. By default the non-production deployment slot has its own hostname that you use to test the bits deployed there. Sometimes, however you may want to prevent users from browsing to your non-production deployment slot while you are testing it.

It is relatively easy to configure your site to block the http request if it is deployed to any non-production slot. For example let’s say I have a site ruslany.azurewebsites.net and I created a deployment slot for it and name the slot as ‘staging‘ (it is possible to give custom names to deployment slots now). The hostname for that deployment slot will be ‘ruslany-staging.azurewebsites.net‘. So to prevent access to the deployment slot from anybody except a few allowed IP addresses I can add the following rewrite rule to my site’s web.config file:

Continue reading “Azure Web Sites – block web access to non-production deployment slots”

RuslanY.net running on Windows Azure Web Sites

I have not been writing any blog posts for a while. That was because for the past two years I have been busy working in a team that develops the Windows Azure Web Sites – a scalable web hosting platform in Windows Azure.

Now that the Windows Azure Web Sites (WAWS) is publicly available I decided to try to move my site from private hosting  to Windows Azure. My site uses WordPress (with MySql database), PHP 5.3, WinCache object and user cache, URL rewriting and many WordPress plugins. With all these different technologies (many of which are not developed by Microsoft), I thought it would be a good test of how WAWS is capable of running web sites that use open source technologies. Plus I expect that my site will be more reliable and available, comparing to my previous private hosting.

I was pleasantly surprised that the migration from private hosting to WAWS hosting was relatively quick and simple. The site has been running successfully in a Shared compute mode for a while now and none of the site’s functionality has been lost or altered. In this post I’ll explain the steps I took to move my site to WAWS hosting. Hopefully it will be useful to those who are planning to migrate their WordPress based site to WAWS.

Continue reading “RuslanY.net running on Windows Azure Web Sites”

Storing URL rewrite mappings in a separate file

When using rewrite maps in IIS URL Rewrite it is very common to have a very large number of entries in a rewrite map. In order to avoid cluttering the configuration file – web.config – with this configuration data the rewrite maps can be defined in a separate configuration file. That file can then be referenced from the web.config file. This post provides an example of how this can be done.

Create a file called rewritemaps.config in the same directory where web.config file is. Open that file in notepad and add the following:

<rewriteMaps>
  <rewriteMap name="Redirects">
    <add key="/oldurl" value="/newurl" />
    <add key="/otheroldurl" value="/othernewurl" />
  </rewriteMap>
</rewriteMaps>

Save this file and then open web.config file in notepad. In the web.config file add the following inside of the <rewrite> section:

<rewriteMaps configSource="rewritemaps.config" />

The configSource attribute tells IIS configuration that the <rewriteMaps> section is defined in a separate file rewritemaps.config. This referenced section can be now uses as if it was defined in the same web.config file. Also, the IIS Manager UI will work well with this referenced file: when you modify or add entries to the rewrite map they will be stored in the rewritemaps.config file.

Here is a complete example web.config file that uses the rewrite map from referenced configuration file:

<configuration>
<system.webServer>
  <rewrite>
    <rewriteMaps configSource="rewritemaps.config"><rewriteMaps>
    <rules>
      <rule name="Redirect rule1 for Redirects">
        <match url=".*" />
        <conditions>
          <add input="{Redirects:{REQUEST_URI}}" pattern="(.+)" />
        </conditions>
        <action type="Redirect" url="{C:1}" appendQueryString="false" />
      </rule>
    </rules>
  </rewrite>
</system.webServer>
</configuration>

The same approach can be used for storing rewrite rules in a separate configuration file, e.g.:

<rules configSource="rewriteRules.config" />

IIS URL Rewrite 2.0 – Release to Web

The IIS URL Rewrite Module 2.0 – RTW is available for download. IIS URL Rewrite v2.0 is an incremental release that includes all the features from version 1.1, and adds extensibility support and outbound response rewriting. More specifically, v2.0 can be used to:

  • Express complex URL rewriting logic by using custom rewrite providers written in .NET.
  • Replace the URLs generated by a web application in the response HTML with a more user friendly and search engine friendly equivalent
  • Fix up the content of any HTTP response by using regular expression pattern matching.
  • Modify HTTP request and response headers and IIS server variables.

For the complete list of features available in this version, refer to Using URL Rewrite Module 2.0.

Install the URL Rewrite 2.0 – RTW

To install the URL Rewrite 2.0, use the download links at the module’s home page at http://www.iis.net/expand/urlrewrite. Note that this is a final, production ready release that is officially supported by Microsoft.

Upgrade notes:

  • If a previous version of URL Rewrite Module, such as v1.0 and v1.1, is already installed then it will be upgraded to the v2.0;
  • If an RC version of the URL Rewrite Module 2.0 is already installed, then it will be upgraded to RTW version.

Install the URL Rewrite Extensibility Samples

An important new feature in this release is the support for custom rewrite providers that can be written in .NET. Custom rewrite providers can be used to implement complex rewrite logic which cannot be expressed by using built-in rewriting functionality.

The URL Rewrite Extensibility Samples include the .NET assemblies and the source code implementing the following providers:

  • DbProvider – this provider can be used to retrieve rewrite mappings from a SQL Server database table by executing a stored procedure;
  • FileMapProvider – this provider can be used to retrieve rewrite mappings stored in a text file;
  • FileContainsProvider – this provider can be used to check if any string in a text file is a substring of the provider’s input string.

Download the URL Rewrite Extensibility Samples from MSDN Code Gallery.

More Information

The following documentation about URL Rewrite 2.0 is available on IIS.net:

Also, visit the URL Rewrite Forum on IIS.NET if you have run into any problems when using the module or have questions or suggestions.

URL Rewrite Module v2 – Release Candidate

The URL Rewrite Module 2.0 – Release Candidate is available for download. The release contains functionality and stability improvements and it is believed to have a quality level suitable for production deployments.

Overview

Microsoft URL Rewrite Module 2.0 for IIS 7 is an incremental release that includes all the features from version 1.1, and adds support for outbound response headers and content rewriting. More specifically, it can be used to:

  • Replace the URLs generated by a web application in the response HTML with a more user friendly and search engine friendly equivalent
  • Modify the links in the HTML markup generated by a web application behind a reverse proxy.
  • Fix up the content of any HTTP response by using regular expression pattern matching.
  • Modify HTTP request headers and IIS server variables.
  • Modify HTTP response headers

Install the URL Rewrite Module 2.0 – RC

To install the URL Rewrite Module 2.0 – RC, use the download links at the module’s home page at http://www.iis.net/extensions/urlrewrite.

Continue reading “URL Rewrite Module v2 – Release Candidate”

Enable PHP Syntax Highlighting on IIS 7

This post describes how to configure IIS 7 to output syntax highlighted source code for PHP files stored on the web server or site. This feature may be useful for development environments when you want to quickly make the source code accessible to other team members.

WARNING: Never attempt to do what is described below on any internet accessible web site! Doing so will greatly compromise the security of your web application.

The HTTP requests for the PHP source code are usually identified by the “.phps” file extension, e.g. http://localhost/index.phps. You will need to configure IIS to understand and handle the HTTP requests with this extension. There are two options for that: to create an IIS handler mapping for “*.phps” or to use the IIS URL Rewrite Module.

Continue reading “Enable PHP Syntax Highlighting on IIS 7”

URL Rewrite Module 2.0 for IIS 7 – Beta

Today IIS team has released the URL Rewrite Module 2.0 for IIS 7 – Beta. This is an incremental release that includes all the features from version 1.1, and adds support for outbound response rewriting. More specifically, it can be used to:

  • Replace the URLs generated by a web application in the response HTML with a more user friendly and search engine friendly equivalent
  • Modify the links in the HTML markup generated by a web application behind a reverse proxy.
  • Fix up the content of any HTTP response by using regular expression pattern matching

Install the URL Rewrite Module 2.0 Beta

wpibadgesilver

or, download:

Note:

Continue reading “URL Rewrite Module 2.0 for IIS 7 – Beta”

IIS 7 URL Rewrite Module support in WordPress 2.8

I am pleased to let everyone know that WordPress development community has added a built-in support for IIS 7 URL Rewrite Module in the upcoming WordPress 2.8 release. Starting with version 2.8 the Permalink Settings page will allow you to easily configure “Pretty Permalinks” URL structure when WordPress is running on IIS 7 with URL Rewrite Module v1.1 installed.

Here is how the process of updating Permalinks structure will look like in WordPress 2.8 on IIS 7:

Continue reading “IIS 7 URL Rewrite Module support in WordPress 2.8”

URL Rewrite Module 1.1 for IIS 7

Today IIS team has released the URL Rewrite Module 1.1 for IIS 7. This is an incremental update that contains fixes to the bugs found since the URL Rewrite Module v1.0 has been released in November 2008. If you have version 1.0 installed (file version of rewrite.dll is 7.1.315.0), it is highly recommended you upgrade to version 1.1.

Install the URL Rewrite Module 1.1 for IIS 7 today!

Install URL Rewrite with Web PI

or, download:

Upgrade from URL Rewrite Module 1.0 release

If you have URL Rewrite Module version 1.0 installed, the installation package upgrades it to version 1.1. All rewrite rules in applicationHost.config and web.config files are preserved during upgrade process.

Continue reading “URL Rewrite Module 1.1 for IIS 7”