Services

  • Drupal CMS Developer
  • Website speed optimisation
  • Drupal 6 to Drupal 8 migrations

Welcome

Welcome, I am a Web Developer based in Madrid, Spain originally from the UK. I studied Computer Science & eBusiness at Loughborough University. I specialise in Content Management System websites

Varnish + CDN - if file doesn't exist fetch from another domain

If you are working with complicated sites with CDNs, especially with imagecache whereby because Drupal says to replace the domain with a CDN domain, the URL called is not Drupal and so never generates the image, then heres the solution. I use varnish as well so am able to say "if the image returns a 404 error, try fetching it from original Drupal domain"

  if (req.url ~ "\.(png|gif|jpg|swf|css|js)$" && req.http.host ~ "^mycdn\.domain\.com" && beresp.status == 404 ) {
      set req.http.Host = "mydrupal.domain.com";
      return(restart);
  }

Basically it says, if the request was to the CDN and it was an image or css or js file, if we get an 404 error then change the request domain to my drupal domain and call varnish back.