Hide

YetaWF Documentation

Display
Print

IIS Proxy (Blue/Green Deploy)

Blue/Green deployment is a technique that can be used with private hosting and many other cloud hosting providers. While your current production site is active and running, you start up a second instance before switching over to the new instance. IIS can be used with a simple proxy that redirects traffic to the new instance. Or tools like nginx can be used to route the traffic.

IIS Proxy

First off, a proxy is defined that accepts all traffic for http://yoursite.com:80 and https://yoursite.com:443.

The proxy doesn't execute any YetaWF code. It merely redirects traffic using the following web.config example:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="www" stopProcessing="true">
          <match url="(.*)" />
          <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
            <add input="{HTTP_HOST}" pattern="^www\.(.*)" />
          </conditions>
          <action type="Redirect" url="https://yoursite.com/{R:0}" />
        </rule>
        <rule name="Redirect to HTTPS" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTPS}" pattern="^OFF$" />
          </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
        </rule>
        <rule name="ReverseProxyInboundRule1" stopProcessing="true">
          <match url="(.*)" />
          <serverVariables>
            <set name="HTTP_X-Forwarded-Proto" value="https" />
            <set name="HTTP_X-Forwarded-Host" value="{HTTP_HOST}" />
            <set name="HTTP_X-Forwarded-Port" value="443" />
            <set name="HTTP_X-Real-IP" value="{REMOTE_ADDR}" />
            <set name="X-Forwarded-For" value="{REMOTE_ADDR}" />
          </serverVariables>
          <action type="Rewrite" url="http://{HTTP_HOST}:5001/{R:1}" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

This sample web.config is very close to what you would use for your site. Of course, you need to change yoursite.com to your actual site name. You also need to change the port number, 5001 in this example, to the port number you want to use for your site. You'll need to reserve two ports for your site (One "blue" and one "green").

This example also includes support to redirect all traffic for www.yoursite.com to yoursite.com (rule "www"). And it also redirects traffic for http://yoursite.com to https://yoursite.com (rule "Redirect to HTTPS"). You may want to keep this as https is preferred. If you need a free certificate for your site, take a look at letsencrypt.org.

The only rule you really need is the rule named "ReverseProxyInboundRule1" in this example. It redirects all traffic for your site to the site of the same name at port 5001. It also includes the X-Forwarded-For header so the receiving blue/green site can respond correctly. This header includes the IP address of the request, which can be used by the receiving site. When the blue/green site renders a page, all the links refer to the real site name (not port 5001 or whatever you chose). In the Site Settings you would still define port 80/443 as the ports used, even though your blue/green site uses another port (5001 in this example). Make sure to turn off Enforce Domain Name and Enforce Port in Site Settings. And set Enforce Security to As Provided in URL.

Once a new site is deployed the web.config file in your proxy is replaced with a new port number in the rule named "ReverseProxyInboundRule1". The proxy restarts automatically and all traffic is redirected to your new site.

YetaWF includes sample proxy web-BLUE.config and web-GREEN.config in the root folder of the solution. You'll need to update the site name and port numbers.

IIS Blue/Green Sites

In addition to the proxy site, you would define two sites in IIS, yoursite-BLUE and yoursite-GREEN with bindings for yoursite:5001 and yoursite:5002 (or whatever ports you're really using). If your proxy redirects all traffic to http://yoursite.com:5001 you only need to including bindings for http and port 5001. https is not used.

This means you have two site folders. You deploy YetaWF to the appropriate folder as usual. You don't need to change any settings in the deployed site (no need to adjust for ports, etc.).

The DeploySite utility used for deployment can assist with Blue/Green deployment as it accepts a command line parameter to deploy either Blue or Green.

Softelvdm.DeploySite Backup yourfile.yaml [Blue|Green]