Distributing Static Content

To resolve low disk space issues when storing large amounts of static content and long load times, CMS developers have made it possible to integrate cloud storage with their own products.

These solutions offer numerous advantages:

  • storing large amounts of data in the cloud is typically cheaper than traditional storage options;
  • by using cloud storage, you can effectively resolve problems with data availability: cloud services crash far less frequently than traditional servers;
  • changing service providers no longer requires you manually migrate large amounts of data;
  • using CDNs significantly increases transfer speeds to users;
  • since users download files from a CDN, there is less stress on the server;
  • cloud service providers guarantee data durability: when data is uploaded to our Cloud Storage, it is immediately replicated on several independent servers and lost data is automatically restored.

Selectel Storage Upload WordPress Plugin

Selectel Storage Upload was designed for synchronizing the files in a WordPress media library with Cloud Storage. The Selectel Storage Upload plugin can be installed either through the WordPress GUI (menu Plugins → Add New) or manually (download). Once the Selectel Storage Upload plugin has been installed, it will be added to the list of available plugins. Activate the plugin to enable it. To configure the plugin:

  1. Log into Cloud Storage and create a container for your media files.
  2. Create an additional user that will have access to the new container.
  3. In the WordPress menu, select Settings → Selectel Upload.
  4. The following page will open:
  5. Enter the username and password for the new user and the container name. The local path to media files and the authorization server URL are entered by default.
  6. Click Save Changes. You can configure the plugin so that all files are uploaded immediately to storage, completely bypassing the WP media library. To do this, check the box Next to Store files only in the Selectel Storage. A domain can be mapped to the container where media is saved. In the field Full URL-path to files, enter the that domain (example: http://uploads.example.com). You can also distribute files without binding a domain. In this case, enter the container address in the Full URL-path to files field (http://xxx.selcdn.com/name).

W3 Total Cache: Distributing Static Content over CDN

To accellerate and optimize your WordPress site, you can use any number of plugins, the most popular of which is W3 Total Cache. This can be used to set up static content distribution via CDN from our Cloud Storage. After the plugin has been installed, check the configuration file. Wp-config.php must contain the following line (if it is not there, you will have to add it manually):

/** Enable W3 Total Cache */ define(‘WP_CACHE’, true); // Added by W3 Total Cache

The file .htacces should look as follows (if necessary, you’ll have to manually make the necessary changes):

#BEGIN W3TC Browser Cache Header append Vary User-Agent env=!dont-vary AddOutputFilterByType DEFLATE text/css text/x-component application/x-j$ # DEFLATE by extension AddOutputFilter DEFLATE js css htm html xml

END W3TC Browser Cache

BEGIN W3TC CDN

<FilesMatch “.(ttf|ttc|otf|eot|woff|font.css)$"> Header set Access-Control-Allow-Origin “*”

END W3TC CDN

Save these changes and then configure the plugin.

  1. Find the Performance item in the main menu.
  2. Choose Performance → General Settings.
  3. On the new page, choose CDN.
  4. Check the box next to Enable.
  5. From the CDN Type list, select Self Hosted/File Transfer Protocol Upload:
  6. Save your changes.
  7. From the main menu, choose Performance → CDN.
  8. Scroll down to the section labeled Configuration:
  9. In the FTP hostname field, enter ftp.selcdn.ru. In the FTP username and FTP password fields, enter your Cloud Storage username and password (remember, when using FTP, it’s better to create a separate user with limited access rights).
  10. For FTP path, enter the container name where your site’s static files will be said. You will have to enter a slash in front of the container name (example: /mysite).
  11. In the Replace site’s hostname with field, enter the canonical name that will be shown as the address of your uploaded files in place of ***.selcdn.com. When your site is loaded, image links will contain the CNAME and not the actual domain.

To make your site work even faster, you can make several CNAME records, which will each be attributed to a specific content type. After these parameters have been entered, click Save all settings. The folder /wp-content/upload will be automatically created inside your container. All static content will be stored here.