Jan 19, 2016

Accelerate the website or fake CDN for Drupal 7

Alexey Doronin
Founder, developer, designer

Browsers can simultaneously handle about 6-8 http requests. To speed up static loading (images, css and js files, and so on), you can create a CDN emulation and return statics from several domains. “Racing” in the browser will be less and this will increase the number of simultaneously processed requests.

1. Create two subdomains — one for images, the other for JS and CSS files. In DNS, write the IP address pointing to the server. For example, take these subdomains: st1.mydomain.com and st2.mydomain.com

2. Create configs for subdomains in NGINX, like these:

server {
  server_name st1.mydomain.com;
  listen 80;
  root /var/www/mydomain.com;
  gzip_static on;
  location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
    expires max;
    log_not_found off;

Root points to the root of our site, the addresses of images and files will be the same.

3. Install Drupal CDN module. In it's settings /admin/config/development/cdn: Testing или Enabled

Next at /admin/config/development/cdn/details write:

http://st1.mydomain.com|.js .css
http://st2.mydomain.com/|.jpg .gif .png

This means that JS and CSS will be given from one domain, and JPG, GIF, PNG, from another.

As a result, the CDN module itself will change all the paths to the required ones, in accordance with the specified rules.