Support

Find answers, guides, and tutorials to supercharge your content delivery.

Manage Multiple Websites with One Zone

Updated on October 4, 2018

There are different options for managing multiple websites with KeyCDN. In this article we're highlighting the two common approaches.

Option 1 - Using one Zone per website

The standard setup is one Zone per website. Each Zone will have its own URL.

Each Zone has its own origin URL

Facts of having one Zone per website:

  • Each Zone can be purged separately
  • Statistics are available for each Zone
  • Each Zone needs to be setup and maintained individually
  • More than 3 Zones will cost $1/zone/month

Option 2 - Using one Zone to manage multiple websites

An alternative approach is to manage multiple websites with one single Zone. We recommend this approach if you plan to deploy multiple websites with the same Zone settings. It is important to note that this setup requires a configuration change on the origin server as well.

there is only one Zone and one Zone URL

Each request from KeyCDN to the origin server contains the HTTP header X-Forwarded-Host (XFH) as shown below in the sample request. XFH contains the Zone Alias of each request. Based on XFH, the origin server needs to deliver the right assets for this particular Zone Alias (see code snippets below on how to configure the origin server). The Pull Zone will maintain a separate cache for each XFH.

Things to be aware of having multiple website in the same Zone:

  • No need to setup multiple Zones
  • No charges for additional Zones
  • The Zone can be purged as a whole or each file separately but not a single website
  • Statistics are available for the whole Zone but not each website

Implement one Zone for multiple websites

  1. In your Zone settings update the Cache Key Host setting to enabled.

  2. Create Zone Aliases for each of your websites that you're planning to use.

  3. Modify your origin server in order to manage X-Forwarded-Host:

    Nginx:

    location / {
        if ( $http_x_forwarded_host = alias.example.com ) {
            root /path/to/website/alias1/;
        }
    }
    

    Apache:

    RewriteEngine on
        RewriteCond "%{HTTP:X-Forwarded-Host}" "alias\.example\.com" [NC]
        RewriteRule "^(.*)$" "/sub/path/$1" [PT]
    
  4. Test your setup. Once you've modified your origin server, test if the origin server is returning content as expected.

Each request from KeyCDN to the origin server contains the X-Forwarded-Host HTTP header:

GET /foobar.jpg HTTP/1.1
Host: your_origin_host
X-Forwarded-Host: <zonename>-<hexid>.kxcdn.com
X-Forwarded-For: 178.82.72.134
X-Forwarded-Scheme: http
X-Pull: KeyCDN
Connection: close
Accept: */*
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36
Accept-Language: en-US,en;q=0.8,de;q=0.6,ja;q=0.4
Cookie: foobar

Supercharge your content delivery 🚀

Try KeyCDN with a free 14 day trial, no credit card required.

Get started
KeyCDN uses cookies to make its website easier to use. Learn more