MaxCDN Blog

How To Streamline Your Traffic with NetDNA’s Full Site Acceleration

December 19, 2012

With the launch of EdgeRules™ and HTTP 1.1 to the origin, you can take advantage of Full Site Acceleration on NetDNA’s CDN.  This will optimize all traffic between your origin servers, our edge servers, and most importantly: your customers.

 

As with any infrastructure change, let’s test the update before pushing it live. This post covers 3 quick steps to safely enable Full Site Acceleration for your site.

 

Step 1: Prepare Your Web Server

The key to a safe migration is making a new hostname to access your content, having the CDN pull from the new location, and finally updating DNS to use the CDN.

First, add the new hostname (such as origin-www.yourdomain.com) to your web server’s configuration:

Apache

Listen 80
NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /www/yourdomain
ServerName www.yourdomain.com
# Other directives here
</VirtualHost>

<VirtualHost *:80>
DocumentRoot /www/yourdomain
ServerName origin-www.yourdomain.com
# Other directives here
</VirtualHost>

Nginx

server {
   listen 80;
   server_name www.yourdomain.com origin-www.yourdomain.com;
   # Other directives here
}

IIS

Make sure you can access your site from both www.yourdomain.com and origin-www.yourdomain.com.

 

Step 2: Create a Pull Zone

Next, open the NetDNA Control Panel and create a new Pull Zone. Use the new hostname (origin-www.yourdomain.com) as the origin server, and add the public URL (www.yourdomain.com) as a custom CDN domain.

If you need to update your Custom CDN Domain later, use Pull Zones > Settings.

Notice the CNAME entry we generate for you (i.e., fullsite.yourcompany.netdna-cdn.com). Don’t make any DNS changes yet — we have testing to do.

 

Step 3: Test the CDN

To test the CDN, change the hostname settings on your local machine.

First, get the Edge Anycast IP by running:
$ host yourdomain.yourcompany.netdna-cdn.com
yourdomain.yourcompany.netdna-cdn.com has address 108.161.188.192
Next, update your hosts file to use this IP for www.yourdomain.com. On Mac/Linux add this line to ~/etc/hosts:
108.161.188.192 www.yourdomain.com
On Windows, the file location is different, so follow these instructions.
You can measure page load time locally (with Chrome or Firebug performance tools), or use an external service like WebPageTest:

 

Use a WebPageTest script to change the DNS settings and navigate to the URL (more about scripting on WPT):

setDns www.yourdomain.com 108.161.188.192
navigate http://www.yourdomain.com

 

Ready? Change your DNS

Once all your tests have passed, point your DNS entry for www.yourdomain.com to the NetDNA CNAME (i.e., yourdomain.yourcompany.netdna-cdn.com). Set a low TTL (5 minutes, 300 seconds) in case you need to switch back. Once you’ve confirmed everything is working, increase the TTL to 24 hours (86400 seconds) or more.

Lastly, make sure to 301 redirect yourdomain.com to www.yourdomain.com, so all traffic is served from the CDN:

Apache

RewriteEngine On
IndexIgnore *
Options +FollowSymLinks -Multiviews -Indexes
RewriteCond %{HTTP_HOST} ^yourdomain.com$ [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]

Nginx

server {
    server_name  yourdomain.com;
    rewrite ^(.*) http://www.yourdomain.com$1 permanent;
}

IIS

<rewrite>
   <rules>
      <rule name="non www to www" enabled="true">
         <match url="(.*)" />
         <conditions>
            <add input="{HTTP_HOST}" negate="true" pattern="^www.([.a-zA-Z0-9]+)$" />
         </conditions>
         <action type="Redirect" url="<a href="http://www.{HTTP_HOST}/{R:0">http://www.{HTTP_HOST}/{R:0</a>}" appendQueryString="true" redirectType="Permanent" />
      </rule>
   </rules>
</rewrite>

That’s it! Your entire site is being served from the edge. To see how NetDNA can help you accelerate your site please contact sales.

  • theavidcruiser

    Will this work with WordPress driven sites? Thanks,

    • http://blog.justindorfman.com jdorfman

      @theavidcruiser:disqus yes it will. You would have to write some custom hooks that will purge the cache (on the CDN) when creating/updating/deleting a Page or Post.

  • diegocerdan

    Very useful service! But what would happend when the user does a POST request with some date. It would hit the original server?

    • http://blog.justindorfman.com jdorfman

      Yes if the request or object is not in cache it will hit the origin.

      • diegocerdan

        So if the POST data or url are different the request would hit the origin.

        • http://blog.justindorfman.com jdorfman

          correct.