====== Brightbox CDN ====== This wiki page provides technical and implementation details for the [[http://www.brightbox.co.uk/services/brightbox-cdn|Brightbox CDN]] service. ===== Technical Overview ===== ==== Global POP Network ==== The global network consists of a global set of POPs (Points of Presence) deployed into major metro areas around the world, with each metro area containing multiple POPs in multiple ISPs. Each POP has a minimum of 4 servers providing caching and DNS mapping services. The current network covers major metro areas in the US, Europe, Australia and Asia (see map below). The strategic network placement and server configurations ensure a quick, reliable, and scalable service. ==== POP locations ==== {{http://www.brightbox.co.uk/upload/images/5/cdn_map.png}} | London | Madrid | New York | San Francisco | Los Angeles | Hong Kong | | Paris | Stockholm | Chicago | Dallas | Atlanta | Seoul | | Amsterdam | Milan | Miami | Seattle | Tokyo | Sydney | | Frankfurt | Washington DC | San Jose | Denver | Singapore | | ==== Cache behaviour ==== The following describes the Brightbox CDN cache behaviour: === Object Expiration/Refreshing === * Cache honours the origin web servers HTTP cache-control headers (see [[cdn#check_your_server_config|Implementation Guide]]) === File Compression === * To improve performance, objects including text, html, css and javascript are compressed (object types already compressed such as jpeg are not compressed) * CDNetworks cache requests uncompressed objects from the origin server * The cache delivers compressed objects to the browser if compression is supported, otherwise uncompressed objects are delivered * Objects less than 1KB in size are not compressed ===== Implementation guide ===== ==== Setup CDN Domain ==== To get started with the Brightbox CDN, you simply need to [[https://control.brightbox.co.uk/login|login to your account]] and click the **"Request Brightbox CDN"** button from the account extras page. Once we've confirmed some details with you regarding your application, we'll configure a unique CDN domain for you. The domain will be a wildcard domain name in the format: ''*..brightcdn.com'' ==== Check your server config ==== Your Brightbox "origin" server (or //servers// if you are running a cluster) must return the correct HTTP headers to work correctly with the CDN cache servers: * **''Content-Type''** (helps identify which objects can be compressed) * **''Content-Length''** (ensures CDN can begin to deliver files as soon as they are received from the origin server when the object doesn't already exist in cache) * **''Last-Modified''** and/or **''ETag''** (the CDN issues an "if-modified-since" request to the origin server saving unnecessary load and bandwidth when the object has not changed) * **''Cache-control''** and/or **''Expires''** (a large expiration time should be specified e.g 10 years) The easiest way to check your server is returning the correct headers, is to request a file directly from your Brightbox server using command line tool curl: $ curl --head http://www.brightbox.co.uk/stylesheets/all.css?1242827686 This will display the HTTP headers supplied by your server, for example: HTTP/1.1 200 OK Date: Tue, 26 May 2009 20:36:58 GMT Server: Apache/2.2.8 (Ubuntu) Phusion_Passenger/2.2.2 mod_ssl/2.2.8 OpenSSL/0.9.8g Last-Modified: Wed, 20 May 2009 13:54:46 GMT ETag: "3214-46a585ebdb580" Accept-Ranges: bytes Content-Length: 12820 Vary: Accept-Encoding Cache-Control: max-age=315360000 Content-Type: text/css If your server is not returning the correct headers, please [[https://www.brightbox.co.uk/customer/support|submit a support ticket]] and we'll assist you with making the necessary changes. ==== Configure your application ==== To make use of the CDN with your Rails application, you'll need to use the built in asset helpers such as ''image_tag'', ''stylesheet_link_tag'' and ''javascript_include_tag'' (which you'll probably be using already). Once we've provided you with your unique CDN domain, you need to configure your application to serve assets from this domain by adding the following to your ''config/environments/production.rb'': ActionController::Base.asset_host = "http://assets%d..brightcdn.com" By default, Brightbox CDN supports only HTTP content. If you need to serve certain parts of your application over SSL, you can disable the CDN for ssl requests like this: ActionController::Base.asset_host = Proc.new { |source, request| if request.ssl? "#{request.protocol}#{request.host_with_port}" else "#{request.protocol}%d..brightcdn.com" % (source.hash % 4) end } **Note:** SSL delivery is available as an optional premium service, please [[http://www.brightbox.co.uk/contact|contact us]] for details.