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
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:
- Log into Cloud Storage and create a container for your media files.
- Create an additional user that will have access to the new container.
- In the WordPress menu, select Settings → Selectel Upload
- The following page will open
- 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.
- 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
# END W3TC Browser Cache # BEGIN W3TC CDN 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 Header set Access-Control-Allow-Origin "*"# END W3TC CDN
Save these changes and then configure the plugin.
- Find the Performance item in the main menu.
- Choose Performance → General Settings.
- On the new page, choose CDN.
- Check the box next to Enable.
- From the CDN Type list, select Self Hosted/File Transfer Protocol Upload:
- Save your changes.
- From the main menu, choose Performance → CDN.
- Scroll down to the section labeled Configuration:
- 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).
- 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).
- 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.