wordpress用cdn_如何为WordPress创建自己的自托管CDN

wordpress用cdn

I know how frustration it is when you try to open a web page and it takes 10-15 seconds to load, so when you own a website its very much understandable why you want it to run fast and get pages loaded within 3-4 seconds.

我知道当您尝试打开网页并花10到15秒钟才能加载时感到沮丧,因此,当您拥有一个网站时,为什么要使其快速运行并在3-4秒钟内加载页面是非常容易理解的。

I use wordpress and a couple of cache plugins to keep my website load fast but when I used Pingdom Website Speed Test to check the load time, it took 4 seconds to load, that is somewhat Okay but when I looked at the performance grade of 73, I knew that I can improve it a lot.

我使用wordpress和几个缓存插件来保持我的网站快速加载,但是当我使用Pingdom网站速度测试来检查加载时间时,它花费了4秒钟来加载,这虽然还可以,但是当我查看性能等级73时,我知道我可以做很多改进。

One of the areas where I got 0 score is “Parallelize downloads across domains” because all the dynamic (PHP) as well as static content (CSS, JS, Images) were getting loaded from my main domain which was causing it to load a bit slow.

我获得0分数的地方之一是“跨域并行下载”,因为所有动态(PHP)和静态内容(CSS,JS,图像)都从我的主域加载,这导致它有点加载了慢。

So I thought of creating my own CDN cookie-less domain for all these static contents. Here I am providing steps to create own own self hosted CDN and setting it up in WordPress WP Cache plugin, that helped me in reducing load time to 2.30 seconds and performance grade of 83.

因此,我想到了为所有这些静态内容创建自己的CDN无cookie域。 在这里,我提供了创建自己的自托管CDN并在WordPress WP Cache插件中进行设置的步骤,这有助于我将加载时间减少到2.30秒,性能等级降低到83。

This is a simple step, just login to your hosting control panel, either cPanel or Plesk and create a subdomain with the name you want. The important thing to notice is that the directory location of the subdomain should be the same as your website. Check below image for better clarity.

这是一个简单的步骤,只需登录到cPanel或Plesk托管控制面板,然后使用所需名称创建一个子域。 需要注意的重要一点是,子域的目录位置应与您的网站相同。 请检查下面的图像,以获得更好的清晰度。

I use Hostgator VPS account and I have my own WebHost Manager, so creating a CNAME for me was very easy. Go to “Edit DNS Zone” and select your zone to edit. You might notice that there are few A names already created for the subdomain you just created. Just delete all of these and create only one CNAME similar to below image.

我使用Hostgator VPS帐户,并且拥有自己的WebHost Manager,因此为我创建CNAME非常容易。 转到“编辑DNS区域”,然后选择要编辑的区域。 您可能会注意到,已经为刚创建的子域创建了几个A名称。 只需删除所有这些,然后仅创建一个与下图类似的CNAME即可。

Our self hosted CDN domain is ready to use but before we make CDN configuration changes to WP Super Cache, we need to make sure our CDN sub-domain remains cookie-less because cookies are useless for static data but it consumes network and browser processing every time a request is sent.

我们已经可以使用自托管的CDN域,但是在对WP Super Cache进行CDN配置更改之前,我们需要确保CDN子域保持无cookie状态,因为cookie对于静态数据无用,但它消耗了网络和浏览器处理的每个发送请求的时间。

Usually WordPress and Google-Analytics sets a lot of cookies, so we need to do some config changes to make our main domain as the primary domain for cookies.

通常WordPress和Google-Analytics会设置很多cookie,因此我们需要进行一些配置更改,以使我们的主域成为cookie的主域。

To set our main domain as primary domain for cookies for google analytics, add following code in the google analytics script.

要将我们的主域设置为Google Analytics(分析)Cookie的主域,请在Google Analytics(分析)脚本中添加以下代码。

_gaq.push(['_setDomainName', 'www.journaldev.com']);

For WordPress, open wp-config.php and add below configuration.

对于WordPress,请打开wp-config.php并添加以下配置。

define ('COOKIE_DOMAIN','www.journaldev.com');

Before you proceed with this step, I would suggest you to load some static contents from your CDN subdomain and make sure it works fine.

在继续执行此步骤之前,建议您从CDN子域中加载一些静态内容,并确保其工作正常。

This part is really easy, just go to CDN tab of WP Super Cache settings and enable CDN support by providing the CDN domain URL.

这部分非常容易,只需转到WP Super Cache设置的CDN选项卡,并通过提供CDN域URL来启用CDN支持。

Thats it, we are using our own self hosted CDN cookie-less domain, after that I checked the performance of my website. Below image shows the loading time reduced from 4.08 seconds to 2.91 seconds that a lot of improvement.

就是这样,在检查了网站的性能之后,我们使用了自己的自托管CDN无cookie域。 下图显示了加载时间从4.08秒减少到2.91秒,这有很多改进。

But I noticed that my performance grade is still 73, it happened because all the static contents were getting loaded from my CDN domain. The solution was easy, I created two more subdomains for my CDN support and then updated WP Super Cache CDN settings to use multiple CDN servers. My final setting looks like below image.

但是我注意到我的性能等级仍然是73,这是因为所有静态内容都是从CDN域中加载的。 解决方案很简单,我为CDN支持创建了两个子域,然后更新了WP Super Cache CDN设置以使用多个CDN服务器。 我的最终设置如下图所示。

Now when I run the website speed test again, I got a time of 2.30 (-1.78 seconds) seconds and performance grade of 83 (+10).

现在,当我再次运行网站速度测试时,我得到的时间为2.30(-1.78秒)秒,性能等级为83(+10)。

wordpress用cdn

原文链接:https://blog.csdn.net/cunchi4221/article/details/107478429?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165934458816782246424187%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=165934458816782246424187&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-11-107478429-null-null.nonecase&utm_term=%E8%87%AA%E5%BB%BAcdn

原创文章,作者:优速盾-小U,如若转载,请注明出处:https://www.cdnb.net/bbs/archives/7021

(0)
上一篇 2022年10月9日 01:58
下一篇 2022年10月9日

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

优速盾注册领取大礼包www.cdnb.net
/sitemap.xml