The drop is always movingYou know that saying about standing on the shoulders of giants? Drupal is standing on a huge pile of midgetsAll content management systems suck, Drupal just happens to suck less.Popular open source software is more secure than unpopular open source software, because insecure software becomes unpopular fast. [That doesn't happen for proprietary software.]Drupal makes sandwiches happen.There is a module for that

Putting a CDN in front of Drupal

Submitted by nk on Wed, 2008-08-20 16:16

We are planning to put a CDN in front of our Drupal install. This CDN is not fancy and is not able to deal with cookies (but it's very cheap). So every anon visitor is going to be served from ANON DOMAIN (the CDN) and every logged in visitor is going to be served from LOGGEDIN DOMAIN (our servers).

This surfaces some questions, such us:

  • what will happen to those visitors who are visiting the wrong domains? For example: an anon visitor visits a url from the LOGGEDIN DOMAIN or vice versa, a logged in user visits a url from the ANON DOMAIN.
  • we have anon comments and they do not need approval. So if an anon visitor posts a comment he would not see his comment at once, as he is getting his page from the CDN, which caches the page.
  • how are we going to track pageviews coming from anon visitors if we let the anon pages handled outside of our infra?

The solutions for these problems are:

  • users visiting the wrong domains: we are going to introduce a cookie for every loggedin visitor to distinct between anon and loggedin.
    • When an anon usr visits the LOGGEDIN DOMAIN then we are going to redirect the user back to the CDN. In PHP we are going to check whether the user is logged in and if not, issue a redirect header.
    • When a loggedin user visits the ANON DOMAIN then a javascript is going to check for the cookie, and if it is present, then will redirect the user. To have this done quickly we will have to put this script at the top of the page, so the visitor will not have to wait for a full pageload.
  • anon comment posted:
    • post will be aimed at the LOGGEDIN DOMAIN
    • give the anon visitor a temporary cookie (5 min expiration, restricted to path where the user posted a comment)
    • anon stays on the LOGGEDIN DOMAIN for this url only and only for a restricted time. (though other anon visitors wont see the new comment until the page cache expires on the CDN side)
  • page view tracking: we are going to embed a 1x1 transparent GIF to the pages. This GIF is going to be generated by the PHP on our own server, this way the PHP will be able to collect stats.

I will post some patches when those go live later this week. That will be interesting, because Drupal issues some harsh cache control headers...

Commenting on this Story is closed.