Last update at :2024-06-01,Edit by888u
WordPress website optimization and acceleration has always been a concern of the majority of webmasters. Today we will mainly introduce the setting method of CDN acceleration for static files (such as pictures, js, css) based on Qiniu Cloud.
CDN or object storage?
At present, many of the customers we are in contact with are based on the object storage
service connected to third-party plug-ins. This itself is actually not a problem, but after contacting it, we found that many users often encounter plug-in selection, There are various problems such as file synchronization and thumbnail generation, so we recommend the CDN
back-to-source acceleration method.
The differences between the two are as follows:
Object storage
stores all static images to a third-party service provider. You don’t even need to save backup files locally, but you need to synchronize the files to a third-party platform, so the docking cost is high, but it is good. The plug-in can help you complete this part of the work;CDN
still saves the files on its own server. When needed, it will grab the cache from its own server and cache it to the CDN node. The configuration is simple. You only need to set up the server. The IP address and return-to-origin host are enough, and you don’t even need to install additional plug-ins;
It can be seen that the main difference is where the files are saved and the configuration cost. If it is a larger site or a site with a lot of files, then using object storage can reduce the operation and maintenance costs (you don’t need to consider too many File synchronization between servers; the files will be very large if the website is migrated), but for small and medium-sized websites, there is definitely no pressure to save such a few pictures on the server hard disk. It will be more convenient to directly use CDN to return to the source. Fast, reducing a lot of operation and maintenance costs and object storage usage costs.
How to configure Qiniu Cloud CDN?
Add integrated CDN acceleration
Create Origin configuration
The origin site configuration generally selects the
Here is a At this time, there is no need to resolve the domain name, only server-side binding is required.
After the binding is completed, you can click Cache configuration
If you are not sure about the cache configuration, it is recommended to just use the Domain name resolution After the configuration is created, it is domain name resolution. Qiniu will provide a cname resolution address, as shown in the figure:
You only need to resolve cname to the specified address in domain name dns resolution.
After the CDN creation and parsing is completed, you only need to replace the static file address in the website. This operation can actually be implemented based on the existing caching plug-in. There is no need to install additional plug-ins. Here is an introduction to commonly used caching plug-ins. Configuration method.
WP Super Cache plugin
WP Fastest Cache plug-in, the top is the CDN address, the bottom is the original address
W3 Total Cache Plug-in
First enable CDN and select Generic Mirror
Then enter the CDN settings to set the CDN domain name
For more plug-ins, you can find them yourself, they are usually available.
After this configuration, the CDN configuration is basically completed. However, as mentioned above, not using the origin domain name is to solve the problem of CDN domain name inclusion. So how does using the IP address solve this problem?
Because if you use an IP address, you still need to bind the CDN domain name to the server, and the CDN domain name is also used directly for access, so you only need to disable it in the WordPress configuration file Find the In this way, you can only access the static files of the website using the CDN address in the future, and other WordPress pages will not be accessible.
Recommended site searches: registration-free virtual space, Korean proxy IP, linux virtual host, registration-free virtual host, Zhenjiang high-defense server, wordpress space, website registration system, US unlimited content host, asp.net space, website registration ,Integrated CDN
in the background of Qiniu Cloud website (you can click here if you have not registered Qiniu Cloud), and configure it according to the page prompts. Here we mainly talk about origin site configuration< /code> and
cache configuration
options.
origin site domain name
or IP address
option. The origin site domain name is the simplest. Just fill in the website domain name directly and return to the origin HOST< /code> also fills in the website domain name. However, after using this method, you can directly use the CDN domain name to access the entire website page. This will cause the pages of the CDN second-level domain name to also be included. This approach is not very good for optimization, so it is recommended.
IP address
.
IP address
setting method, as shown in the figure:
origin site test
, which will test whether the configuration is correct, so you need to complete the CDN domain name binding operation of the server before testing. This operation is the same as binding the main domain name of the website before. , but it should be noted that the website directory bound to the CDN domain name needs to be the same as the main domain name directory, or you can directly add a CDN domain name to the original configuration
.
Origin site test
below. If there is no problem with the configuration, it will pass.
default
of 30 days. The main reminder is to remind you that Ignore URL parameters
is recommended to be set to off. If it is turned on, it will As a result, the cache cannot be cleared immediately after the theme and plug-in are updated, which may affect normal access to the website.
WordPress settings
Prohibit inclusion of CDN domain name pages
wp-config.php
CDN domain name is enough.
wp-config.php
file under the root directory of the website, edit the file and add the following code after define('WP_DEBUG', false);:
if( $_SERVER['HTTP_HOST'] == 'Replace with CDN domain name' ) {
header("HTTP/1.1 404 Not Found");
exit;
}
发表评论