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.
Facts of having one zone per website:
- Each zone (website) can be purged separately
- Statistics are available for each zone (website)
- Each zone needs to be setup and maintained individually
- More than 5 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.
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 zonealias of each request. Based on XFH, the origin server needs to deliver the right assets for this particular zonealias (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
- Enable the “Cache Key Host” option in your zone’s advanced features section.
- Create Zonealiases for each of your websites that you’re planning to use.
- Modify your origin server in order to manage X-Forwarded-Host (XFH).
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]
- 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 HTTP header X-Forwarded-Host
GET /foobar.jpg HTTP/1.1 Host: your_origin_host X-Forwarded-Host: <zonename>-<id>.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