Using Content Delivery Networks
with Drupal
TriDUG – March 2015
What areCDNs
A content delivery network or content distribution
network (CDN) isalarge distributed system of
serversdeployed in multipledatacentersacrossthe
Internet. Thegoal of aCDN isto servecontent to
end-userswith high availability and high
performance.
Traditional Delivery
Theserver in theimage
representseither a
singleserver or asingle
datacenter with aproxy
front end (e.g. Varnish /
nGinx )
CDN Delivery
Theseserversrepresent
different datacenters
that can belocated in
different areasof the
world.
Clientsget served
information from the
best site.
Why UseaCDN
● Increasethenumber of usersthat can accessthesite
without degradation.
● Ensurequality user experienceby having all or parts
of apageloaded from serverscloseto them
● Lower theimpact of usersaccessing largefiles
CDN Basics
● Theterm origin refersto thesourceserver
● CDN clustersinstancesaredefined by aspecial DNS
host name, e.g. <dist id>.cloudfront.net
● TheCDN'sDNSentry will berouted thru an
(expensive) load balancing routing system that
determinesthebest server to servicetherequest.
● DNSsettingsand URL rewriting areused to cause
clientsto get theinformation from thecluster.
● Filescached on theCDN all have“expiration” times
that can beset/controlled in variousmanners.
Anatomy of A CDN Request
● Client browser requestsaCDN cached fileviaan
embedded URL or just entering theURL.
● TheCDN'sload balancing routerswill determinetheCDN
server to usebased on clientslocation, etc.
● TheCDN server selected looksto seeif thisfileexists.
● If thefileexists, it checksthe“expiration” date.
● If thefileexistsand hasnot expired, it returnsthecache
version. Theorigin server doesno work.
● Otherwise, if possible, theCDN will ask theorigin server
for afresh copy of thefileand send it to theclient.
CDN Services
● Akamai Technologies
● Amazon CloudFront
● WindowsAzureCDN
● EdgeCast Networks
● RackspaceCloud Files
● Vimeo
● YouTube
● ...and many more
Selecting aCDN Service
● Dependson your needs, e.g. Mediaonly, web only,
and thelike.
● Regionsyou need served.
● Dependson theclient'spricerangeand quality of
serviceneeds.
● HTTPSsupport / costs
(Note: Googleand other search enginesarestarting to
givepreferenceto sitesthat areavailableviaHTTPS)
Common waysCDNs
areused with Drupal
● Mediaand largefiledelivery (e.g. YouTube, Vimeo,
and others)
● Static filedelivery (CSS, Images, JS, and thelike)
● Full anonymoussitecaching
MediaDelivery
● SiteDNSpointsto origin
● Content pointsto CDN DNS
when needed
● Filesareadded viaCDNsadmin
interface
Pros
● Largefilesdelivered efficiently
● Normal Drupal behavior
Cons
● CDN delivered filesmay haveto
bemanually set up/managed.
Static FileDelivery
● SiteDNSpointsto origin
● CDN modulecan automatically
rewritestatic URLsto CDN
DNS
● Filesareautomatically cached
Pros
● Server load reduced
● Set and (almost) forget
Cons
● Can beadelay updating files
that areREPLACED.
Full SiteDelivery
● SiteDNSpointsto CDN cluster
● No special moduleslikeCDN
needed, filesareautomatically
added to thecache.
Pros
● Supportsmost clientswith least
impact on origin
Cons
● Morecomplex set up
● Need to defineprocessesto allow
content managersto refresh
updated content
Challengesto using CDNsand Drupal
● CDNsservecached content based on URLs
● User based Drupal sitescan havedifferent content
displayed using thesameURL, e.g. /user
● Content editorswant to seechangesimmediately
and not wait for cacheto refresh
● Network managerswant cacheto last along timeto
lower server load
Selecting aCDN mode
A quick ruleof thumb for deciding between Full site
delivery and Static filedelivery is:
● Doesyour sitesupport individual users?
Yes- UseStatic filedelivery
No – UseFull site
Note: CDNsalso havevarioussettingsthat may let
you createahybrid site, e.g. deliver certain areasvia
CDN but let Cart or Forum or... areasbestatic only.
SomeUseful Modules
● CDN isuseful for setting up static fileservices
http://drupal.org/project/cdn
● CloudFront Refresh (my module:) )
http://drupal.org/sandbox/cgmonroe/2454357
● AdvancedAggregation – Doesabetter job of css
and javascript aggregation
http://drupal.org/project/advagg
A CaseStudy
● A collegehasacoach who lovesto set sports
records... likeaplayer scoring 130+ point in agame,
which leadsto massiveload on their main web site.
● Thecommunicationsdepartment isvery proactivein
updating thecontent and want visitorsto seethings
immediately
● Themain websiteisaccessed by anonymoususers
with theexception of variouscontent manager
● They want to support HTTPSto get the“Google”
ranking boost.
Strategy Used
● UseCloudFront CDN serviceasafull sitedelivery
service.
● UseServer NameIndication Certificatesto allow
HTTPSon multipleDNSnames
● Use“origin” DNSentry to bypassCDN for content
editors
● Writeacustom moduleto allow content to easily be
refreshed on theCDN cluster
Set up CloudFront Distro
Set up CloudFront Distro
Set UpApplicationAWSUser
Set up DNS
● Thewww.college.edu siteisset up with aCNAME
entry thepointsto theCloudfront.net DNSentry
● The“edit” siteusesorigin.college.edu and pointsto
theserver'sIPaddress
Setup theCertificates
● Get and SNI SSL certificatewith all theDNSnames
you want thesiteto beknown as. E.g.
origin.college.edu and www.college.edu
● Install thecertificateon theAmazon CF Distribution
(seeAmazon docs)
● Install thecertificateon theorigin server
.htaccessSetup
To set aspecific expiresheader / time... look for thesection likethisand modify asneeded.
NOTE: Drupal pagesexpiretimebased on Pagecachetimesetting in config->devel-
>performance.
# Requires mod_expires to be enabled.
<IfModule mod_expires.c>
  # Enable expirations.
  ExpiresActive On
  # Short expires for testing.
  ExpiresDefault "access plus 1 minutes"
  <FilesMatch .php$>
    # Do not allow PHP scripts to be cached unless they explicitly send cache
    # headers themselves. Otherwise all scripts would have to overwrite the
    # headers setby mod_expires if they want another caching behavior. This may
    # fail if an error occurs early in the bootstrap process, and it may cause
    # problems if a non­Drupal PHP file is installed in a subdirectory.
    ExpiresActive Off
  </FilesMatch>
</IfModule>
.htaccessSetup
Redirect login'sto origin site:
 # Redirect logins to non­CDN site
  RewriteCond %{HTTP_HOST} !^origin.college.edu [NC]
  RewriteRule ^user/login$ https://origin.college.edu/user/login [R=301,L]
  RewriteCond %{HTTP_HOST} !^origin.college.edu [NC]
  RewriteRule ^user$ https://origin.college.edu/user [R=301,L]
.htaccessSetup
If you usecustom fonts, you will need to prevent CORS
security errors, usethefollowing. NOTE: needsto be
tweaked if you want to limit to specific sites.
<IfModule mod_headers.c>
   Header set Access­Control­Allow­Origin *
#  SetEnvIf Origin "^(.*.college.edu)$" 
ORIGIN_SUB_DOMAIN=$1
#  <FilesMatch ".woff$">
#    Header set Access­Control­Allow­Origin "%
{ORIGIN_SUB_DOMAIN}e" env=ORIGIN_SUB_DOMAIN
#  </FilesMatch>
</IfModule>
Settings.php Setup
Thefollowing codeletstheCDN support HTTPS. Needsto bein
thesettings.php file.
if (isset($_SERVER['HTTP_CLOUDFRONT_FORWARDED_PROTO']) &&
     $_SERVER['HTTP_CLOUDFRONT_FORWARDED_PROTO'] == 'https') {
  $_SERVER['HTTPS'] = 'on';
  $_SERVER['HTTP_X_FORWARDED_PROTO'] = 'https';
}
// The following are only needed if the 'non­CDN' site can be 
// accessed by more than 1 host name E.g., initially an internal
// DNS entry and then moved to a client DNS entry.
if ( isset($_SERVER['HTTP_HOST']) && 
      $_SERVER['HTTP_HOST'] == 'college­origin.longsight.com') {
  $_SERVER['HTTP_HOST'] = 'origin.college.edu';
}
Setup CloudFront Refresh Module
● Get thenew CloudFront Refresh modulefrom itssandbox:
http://drupal.org/sandbox/cgmonroe/2454357 
● Get dependancies:
http://drupal.org/project/libraries(if needed)
http://drupal.org/project/awssdk
● Follow theCloudFront Refresh install instructions
CloudFront Refresh
● Tracksupdated nodesand
sendsinvalidaterequest
when sitecacheiscleared
● Allowsmanually entering
URL to refresh non-html
files
● Statuspageto track refresh
requests
● Someother codeto improve
CDN hit rates
Results
● Entiresiteisserviced viaCDN with low hit rateon
main server
● Fast responseeven under load
● Content editor can instantly seethechangesthey are
editing becauseloginsget redirected to theorigin
site.
● CloudFront Refresh modulemakeiseasy for
updatesto be“pushed” out to CDN.
SomeTroubleshooting/Testing Tips
● curl -I -L http://www.college.edu/<path>
Thisgetstheheadersfor thepath with expiretimeand other
information. For example, you can check theexpiretimeon
pagescoming from theorigin server.
● Chrome/ Firebug network load tab
Thiscan beused to determinewhat isbeing loaded from
which server (or not being loaded).
● Think ahead.
CDNsaresimilar to DNSserverswith propagation delays. If a
siteisgoing to havemajor changes, set theorigin expiretime
to alow valueaday or so before.
Questions?

More Related Content

PPTX
3. v sphere big data extensions
PPTX
QNAP SMB Presentation en Español
PDF
Storage as a Service with Gluster
PPTX
Caching
PDF
Gluster Webinar: Introduction to GlusterFS v3.3
PDF
Introduction to GlusterFS Webinar - September 2011
PDF
Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...
PDF
Implementing High Availability Caching with Memcached
3. v sphere big data extensions
QNAP SMB Presentation en Español
Storage as a Service with Gluster
Caching
Gluster Webinar: Introduction to GlusterFS v3.3
Introduction to GlusterFS Webinar - September 2011
Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...
Implementing High Availability Caching with Memcached

What's hot (19)

PDF
Gluster Webinar: Introduction to GlusterFS
PDF
AWS Workshop 101
PPTX
Hadoop Meetup Jan 2019 - Hadoop On Azure
PDF
caching2012.pdf
PDF
Evaluating NoSQL Performance: Time for Benchmarking
PDF
Globus Endpoint Setup and Configuration - XSEDE14 Tutorial
PDF
Multi-Region Cassandra Clusters
PDF
Using advanced options in MariaDB Connector/J
ODP
GlusterFS Architecture - June 30, 2011 Meetup
PPTX
Hadoop Meetup Jan 2019 - Mounting Remote Stores in HDFS
ODP
Caching Strategies
PDF
Hbase: an introduction
PPTX
Cassandra Performance and Scalability on AWS
PDF
Ceph Day Beijing: Containers and Ceph
PPT
How to Design a Scalable Private Cloud
PDF
Webinar Sept 22: Gluster Partners with Redapt to Deliver Scale-Out NAS Storage
PDF
Red Hat Global File System (GFS)
PDF
PostgreSQL Disaster Recovery with Barman
ODP
Dustin Black - Red Hat Storage Server Administration Deep Dive
Gluster Webinar: Introduction to GlusterFS
AWS Workshop 101
Hadoop Meetup Jan 2019 - Hadoop On Azure
caching2012.pdf
Evaluating NoSQL Performance: Time for Benchmarking
Globus Endpoint Setup and Configuration - XSEDE14 Tutorial
Multi-Region Cassandra Clusters
Using advanced options in MariaDB Connector/J
GlusterFS Architecture - June 30, 2011 Meetup
Hadoop Meetup Jan 2019 - Mounting Remote Stores in HDFS
Caching Strategies
Hbase: an introduction
Cassandra Performance and Scalability on AWS
Ceph Day Beijing: Containers and Ceph
How to Design a Scalable Private Cloud
Webinar Sept 22: Gluster Partners with Redapt to Deliver Scale-Out NAS Storage
Red Hat Global File System (GFS)
PostgreSQL Disaster Recovery with Barman
Dustin Black - Red Hat Storage Server Administration Deep Dive
Ad

Viewers also liked (18)

PPT
Intro to CSS Selectors in Drupal
PPT
Content Delivery Networks
PPTX
A Social Content Delivery Network for Scientific Cooperation: Vision, Design...
PPTX
What’s the Difference between an Application Delivery Network and a Content D...
PPTX
Content Delivery Network
ODP
CDN - Content Delivery Network
PPT
How a Content Delivery Network Can Help Speed Up Your Website
PPTX
The Evolution of the Content Delivery Network
PPT
Joomla Content Delivery Networks
PPT
Tvb Media Comparisons 2010 Persons
PPT
Space Camp - Barcelona - English
PPTX
Language Policy In Papua And Zambia
PPT
Study Abroad In A Transparent World
PPTX
I days v3
PPTX
Blood components case study presentation july 2013
DOC
φε το βιβλίο που μου έκανε συντροφιά 3
DOC
Comidase bebidas com_texto
PPTX
Solucion lectura 3[1]
Intro to CSS Selectors in Drupal
Content Delivery Networks
A Social Content Delivery Network for Scientific Cooperation: Vision, Design...
What’s the Difference between an Application Delivery Network and a Content D...
Content Delivery Network
CDN - Content Delivery Network
How a Content Delivery Network Can Help Speed Up Your Website
The Evolution of the Content Delivery Network
Joomla Content Delivery Networks
Tvb Media Comparisons 2010 Persons
Space Camp - Barcelona - English
Language Policy In Papua And Zambia
Study Abroad In A Transparent World
I days v3
Blood components case study presentation july 2013
φε το βιβλίο που μου έκανε συντροφιά 3
Comidase bebidas com_texto
Solucion lectura 3[1]
Ad

Similar to Using Content Delivery Networks with Drupal (20)

PDF
Cdn reviews.com
PPTX
CloudFlare CDN + Drupal
PPTX
Introduction to Content Delivery Networks
PDF
Cloud CDN User Manual Guide
PPTX
crit_think_intro classroom slides class notes
PPTX
Content Devilery Network
PDF
Content Delivery Network - Exploring the Power
PPTX
determining the delivery network needs
PDF
Embedded CDNs in 2023
PDF
Improve WordPress Website Performance with a Content Delivery Network: Better...
PDF
SPA2015: Hooman Beheshti – The Future of CDNs
PPTX
What is CDN ? how CDN work?
PDF
InfoWorld
PPTX
(CDN) Content Delivery Network
PPT
PDF
Content Delivery Networks
DOCX
Content Delivery Network – CDN
PDF
PLNOG 6: Christian Kaufmann - How Akamai delivers your packets - the insight
PDF
PLNOG 6: Christian Kaufmann - How Akamai delivers your packets - the insight
Cdn reviews.com
CloudFlare CDN + Drupal
Introduction to Content Delivery Networks
Cloud CDN User Manual Guide
crit_think_intro classroom slides class notes
Content Devilery Network
Content Delivery Network - Exploring the Power
determining the delivery network needs
Embedded CDNs in 2023
Improve WordPress Website Performance with a Content Delivery Network: Better...
SPA2015: Hooman Beheshti – The Future of CDNs
What is CDN ? how CDN work?
InfoWorld
(CDN) Content Delivery Network
Content Delivery Networks
Content Delivery Network – CDN
PLNOG 6: Christian Kaufmann - How Akamai delivers your packets - the insight
PLNOG 6: Christian Kaufmann - How Akamai delivers your packets - the insight

More from cgmonroe (12)

PDF
Structured SEO Data Overview and How To
PDF
Structured SEO Data: An overview and how to for Drupal
PDF
Tips on Securing Drupal Sites - DrupalCamp Atlanta (DCA)
PDF
Tips on Securing Drupal Sites
PDF
Becoming "Facet"-nated with Search API
ODP
Intro to drupal module internals asheville
ODP
Solr facets and custom indices
PPTX
HTML Purifier, WYSIWYG, and TinyMCE
PPTX
Using the Features API
PPTX
The Drupal Strongarm Module - Tips and Tricks.
PPT
Drupal Workflow Concepts
PPTX
TriDUG WebFM Presentation
Structured SEO Data Overview and How To
Structured SEO Data: An overview and how to for Drupal
Tips on Securing Drupal Sites - DrupalCamp Atlanta (DCA)
Tips on Securing Drupal Sites
Becoming "Facet"-nated with Search API
Intro to drupal module internals asheville
Solr facets and custom indices
HTML Purifier, WYSIWYG, and TinyMCE
Using the Features API
The Drupal Strongarm Module - Tips and Tricks.
Drupal Workflow Concepts
TriDUG WebFM Presentation

Recently uploaded (20)

PDF
Convolutional neural network based encoder-decoder for efficient real-time ob...
PDF
Improvisation in detection of pomegranate leaf disease using transfer learni...
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PPTX
Configure Apache Mutual Authentication
PPTX
Training Program for knowledge in solar cell and solar industry
PPT
Geologic Time for studying geology for geologist
PDF
giants, standing on the shoulders of - by Daniel Stenberg
PDF
Flame analysis and combustion estimation using large language and vision assi...
PDF
4 layer Arch & Reference Arch of IoT.pdf
PDF
Early detection and classification of bone marrow changes in lumbar vertebrae...
PDF
A review of recent deep learning applications in wood surface defect identifi...
PPTX
GROUP4NURSINGINFORMATICSREPORT-2 PRESENTATION
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PPTX
Module 1 Introduction to Web Programming .pptx
PDF
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
PDF
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
PDF
OpenACC and Open Hackathons Monthly Highlights July 2025
PDF
5-Ways-AI-is-Revolutionizing-Telecom-Quality-Engineering.pdf
PDF
Transform-Quality-Engineering-with-AI-A-60-Day-Blueprint-for-Digital-Success.pdf
PPTX
Build Your First AI Agent with UiPath.pptx
Convolutional neural network based encoder-decoder for efficient real-time ob...
Improvisation in detection of pomegranate leaf disease using transfer learni...
NewMind AI Weekly Chronicles – August ’25 Week III
Configure Apache Mutual Authentication
Training Program for knowledge in solar cell and solar industry
Geologic Time for studying geology for geologist
giants, standing on the shoulders of - by Daniel Stenberg
Flame analysis and combustion estimation using large language and vision assi...
4 layer Arch & Reference Arch of IoT.pdf
Early detection and classification of bone marrow changes in lumbar vertebrae...
A review of recent deep learning applications in wood surface defect identifi...
GROUP4NURSINGINFORMATICSREPORT-2 PRESENTATION
sustainability-14-14877-v2.pddhzftheheeeee
Module 1 Introduction to Web Programming .pptx
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
OpenACC and Open Hackathons Monthly Highlights July 2025
5-Ways-AI-is-Revolutionizing-Telecom-Quality-Engineering.pdf
Transform-Quality-Engineering-with-AI-A-60-Day-Blueprint-for-Digital-Success.pdf
Build Your First AI Agent with UiPath.pptx

Using Content Delivery Networks with Drupal

  • 1. Using Content Delivery Networks with Drupal TriDUG – March 2015
  • 2. What areCDNs A content delivery network or content distribution network (CDN) isalarge distributed system of serversdeployed in multipledatacentersacrossthe Internet. Thegoal of aCDN isto servecontent to end-userswith high availability and high performance.
  • 3. Traditional Delivery Theserver in theimage representseither a singleserver or asingle datacenter with aproxy front end (e.g. Varnish / nGinx )
  • 4. CDN Delivery Theseserversrepresent different datacenters that can belocated in different areasof the world. Clientsget served information from the best site.
  • 5. Why UseaCDN ● Increasethenumber of usersthat can accessthesite without degradation. ● Ensurequality user experienceby having all or parts of apageloaded from serverscloseto them ● Lower theimpact of usersaccessing largefiles
  • 6. CDN Basics ● Theterm origin refersto thesourceserver ● CDN clustersinstancesaredefined by aspecial DNS host name, e.g. <dist id>.cloudfront.net ● TheCDN'sDNSentry will berouted thru an (expensive) load balancing routing system that determinesthebest server to servicetherequest. ● DNSsettingsand URL rewriting areused to cause clientsto get theinformation from thecluster. ● Filescached on theCDN all have“expiration” times that can beset/controlled in variousmanners.
  • 7. Anatomy of A CDN Request ● Client browser requestsaCDN cached fileviaan embedded URL or just entering theURL. ● TheCDN'sload balancing routerswill determinetheCDN server to usebased on clientslocation, etc. ● TheCDN server selected looksto seeif thisfileexists. ● If thefileexists, it checksthe“expiration” date. ● If thefileexistsand hasnot expired, it returnsthecache version. Theorigin server doesno work. ● Otherwise, if possible, theCDN will ask theorigin server for afresh copy of thefileand send it to theclient.
  • 8. CDN Services ● Akamai Technologies ● Amazon CloudFront ● WindowsAzureCDN ● EdgeCast Networks ● RackspaceCloud Files ● Vimeo ● YouTube ● ...and many more
  • 9. Selecting aCDN Service ● Dependson your needs, e.g. Mediaonly, web only, and thelike. ● Regionsyou need served. ● Dependson theclient'spricerangeand quality of serviceneeds. ● HTTPSsupport / costs (Note: Googleand other search enginesarestarting to givepreferenceto sitesthat areavailableviaHTTPS)
  • 10. Common waysCDNs areused with Drupal ● Mediaand largefiledelivery (e.g. YouTube, Vimeo, and others) ● Static filedelivery (CSS, Images, JS, and thelike) ● Full anonymoussitecaching
  • 11. MediaDelivery ● SiteDNSpointsto origin ● Content pointsto CDN DNS when needed ● Filesareadded viaCDNsadmin interface Pros ● Largefilesdelivered efficiently ● Normal Drupal behavior Cons ● CDN delivered filesmay haveto bemanually set up/managed.
  • 12. Static FileDelivery ● SiteDNSpointsto origin ● CDN modulecan automatically rewritestatic URLsto CDN DNS ● Filesareautomatically cached Pros ● Server load reduced ● Set and (almost) forget Cons ● Can beadelay updating files that areREPLACED.
  • 13. Full SiteDelivery ● SiteDNSpointsto CDN cluster ● No special moduleslikeCDN needed, filesareautomatically added to thecache. Pros ● Supportsmost clientswith least impact on origin Cons ● Morecomplex set up ● Need to defineprocessesto allow content managersto refresh updated content
  • 14. Challengesto using CDNsand Drupal ● CDNsservecached content based on URLs ● User based Drupal sitescan havedifferent content displayed using thesameURL, e.g. /user ● Content editorswant to seechangesimmediately and not wait for cacheto refresh ● Network managerswant cacheto last along timeto lower server load
  • 15. Selecting aCDN mode A quick ruleof thumb for deciding between Full site delivery and Static filedelivery is: ● Doesyour sitesupport individual users? Yes- UseStatic filedelivery No – UseFull site Note: CDNsalso havevarioussettingsthat may let you createahybrid site, e.g. deliver certain areasvia CDN but let Cart or Forum or... areasbestatic only.
  • 16. SomeUseful Modules ● CDN isuseful for setting up static fileservices http://drupal.org/project/cdn ● CloudFront Refresh (my module:) ) http://drupal.org/sandbox/cgmonroe/2454357 ● AdvancedAggregation – Doesabetter job of css and javascript aggregation http://drupal.org/project/advagg
  • 17. A CaseStudy ● A collegehasacoach who lovesto set sports records... likeaplayer scoring 130+ point in agame, which leadsto massiveload on their main web site. ● Thecommunicationsdepartment isvery proactivein updating thecontent and want visitorsto seethings immediately ● Themain websiteisaccessed by anonymoususers with theexception of variouscontent manager ● They want to support HTTPSto get the“Google” ranking boost.
  • 18. Strategy Used ● UseCloudFront CDN serviceasafull sitedelivery service. ● UseServer NameIndication Certificatesto allow HTTPSon multipleDNSnames ● Use“origin” DNSentry to bypassCDN for content editors ● Writeacustom moduleto allow content to easily be refreshed on theCDN cluster
  • 22. Set up DNS ● Thewww.college.edu siteisset up with aCNAME entry thepointsto theCloudfront.net DNSentry ● The“edit” siteusesorigin.college.edu and pointsto theserver'sIPaddress
  • 23. Setup theCertificates ● Get and SNI SSL certificatewith all theDNSnames you want thesiteto beknown as. E.g. origin.college.edu and www.college.edu ● Install thecertificateon theAmazon CF Distribution (seeAmazon docs) ● Install thecertificateon theorigin server
  • 24. .htaccessSetup To set aspecific expiresheader / time... look for thesection likethisand modify asneeded. NOTE: Drupal pagesexpiretimebased on Pagecachetimesetting in config->devel- >performance. # Requires mod_expires to be enabled. <IfModule mod_expires.c>   # Enable expirations.   ExpiresActive On   # Short expires for testing.   ExpiresDefault "access plus 1 minutes"   <FilesMatch .php$>     # Do not allow PHP scripts to be cached unless they explicitly send cache     # headers themselves. Otherwise all scripts would have to overwrite the     # headers setby mod_expires if they want another caching behavior. This may     # fail if an error occurs early in the bootstrap process, and it may cause     # problems if a non­Drupal PHP file is installed in a subdirectory.     ExpiresActive Off   </FilesMatch> </IfModule>
  • 25. .htaccessSetup Redirect login'sto origin site:  # Redirect logins to non­CDN site   RewriteCond %{HTTP_HOST} !^origin.college.edu [NC]   RewriteRule ^user/login$ https://origin.college.edu/user/login [R=301,L]   RewriteCond %{HTTP_HOST} !^origin.college.edu [NC]   RewriteRule ^user$ https://origin.college.edu/user [R=301,L]
  • 26. .htaccessSetup If you usecustom fonts, you will need to prevent CORS security errors, usethefollowing. NOTE: needsto be tweaked if you want to limit to specific sites. <IfModule mod_headers.c>    Header set Access­Control­Allow­Origin * #  SetEnvIf Origin "^(.*.college.edu)$"  ORIGIN_SUB_DOMAIN=$1 #  <FilesMatch ".woff$"> #    Header set Access­Control­Allow­Origin "% {ORIGIN_SUB_DOMAIN}e" env=ORIGIN_SUB_DOMAIN #  </FilesMatch> </IfModule>
  • 27. Settings.php Setup Thefollowing codeletstheCDN support HTTPS. Needsto bein thesettings.php file. if (isset($_SERVER['HTTP_CLOUDFRONT_FORWARDED_PROTO']) &&      $_SERVER['HTTP_CLOUDFRONT_FORWARDED_PROTO'] == 'https') {   $_SERVER['HTTPS'] = 'on';   $_SERVER['HTTP_X_FORWARDED_PROTO'] = 'https'; } // The following are only needed if the 'non­CDN' site can be  // accessed by more than 1 host name E.g., initially an internal // DNS entry and then moved to a client DNS entry. if ( isset($_SERVER['HTTP_HOST']) &&        $_SERVER['HTTP_HOST'] == 'college­origin.longsight.com') {   $_SERVER['HTTP_HOST'] = 'origin.college.edu'; }
  • 28. Setup CloudFront Refresh Module ● Get thenew CloudFront Refresh modulefrom itssandbox: http://drupal.org/sandbox/cgmonroe/2454357  ● Get dependancies: http://drupal.org/project/libraries(if needed) http://drupal.org/project/awssdk ● Follow theCloudFront Refresh install instructions
  • 29. CloudFront Refresh ● Tracksupdated nodesand sendsinvalidaterequest when sitecacheiscleared ● Allowsmanually entering URL to refresh non-html files ● Statuspageto track refresh requests ● Someother codeto improve CDN hit rates
  • 30. Results ● Entiresiteisserviced viaCDN with low hit rateon main server ● Fast responseeven under load ● Content editor can instantly seethechangesthey are editing becauseloginsget redirected to theorigin site. ● CloudFront Refresh modulemakeiseasy for updatesto be“pushed” out to CDN.
  • 31. SomeTroubleshooting/Testing Tips ● curl -I -L http://www.college.edu/<path> Thisgetstheheadersfor thepath with expiretimeand other information. For example, you can check theexpiretimeon pagescoming from theorigin server. ● Chrome/ Firebug network load tab Thiscan beused to determinewhat isbeing loaded from which server (or not being loaded). ● Think ahead. CDNsaresimilar to DNSserverswith propagation delays. If a siteisgoing to havemajor changes, set theorigin expiretime to alow valueaday or so before.