如何在WordPress中设置CloudFlare Free CDN

Do you want to use Cloudflare CDN on your WordPress site?

您是否要在WordPress网站上使用Cloudflare CDN?

Cloudflare is one of the best WordPress CDN and firewall services available in the market. They offer a free CDN that speeds up your website along with a suite of powerful security features for small business websites.

Cloudflare是市场上最好的WordPress CDN和防火墙服务之一。 他们提供免费的CDN,可加快您的网站的速度,并为小型企业网站提供了一套强大的安全功能。

The challenge is that many entry-level users are not able to utilize Cloudflare because they think it is hard to set up.

挑战在于,许多入门级用户无法使用Cloudflare,因为他们认为很难设置。

In this guide, we will walk you through a complete Cloudflare setup in WordPress to help you improve your website speed.

在本指南中,我们将引导您完成WordPress中完整的Cloudflare设置,以帮助您提高网站速度。

如何在WordPress中设置CloudFlare Free CDN_第1张图片

Table of Contents:

目录

  • What is CDN? Why You Need It?
  • 什么是CDN? 为什么需要它?
  • What is Cloudflare CDN?什么是Cloudflare CDN?
  • MaxCDN vs CloudflareMaxCDN与Cloudflare
  • Setting Up Cloudflare CDN in WordPress在WordPress中设置Cloudflare CDN
  • Method 1: Cloudflare Setup from Web Host cPanel (SiteGround)方法1:从Web Host cPanel(SiteGround)设置Cloudflare
  • Method 2: Setting Up Cloudflare Manually方法2:手动设置Cloudflare
  • Configuring Most Important Cloudflare Settings配置最重要的Cloudflare设置
  • Optimizing Cloudflare for WordPress为WordPress优化Cloudflare
什么是CDN? 为什么您的站点需要CDN? (What is CDN? Why You Need a CDN for Your Site?)

A CDN or Content Delivery Network is a system of distributed servers which helps deliver your website files faster to the users based on their geographic location.

CDN或内容交付网络是一个分布式服务器系统,可帮助根据用户的地理位置将网站文件更快地交付给用户。

Typically, a web hosting service serves your website visitors from a single location. All the users access the same server, no matter where they are located. This can result in a delay in content delivery for users living further away from your website’s central hosting server.

通常,网络托管服务从一个位置为您的网站访问者提供服务。 无论用户位于何处,所有用户都访问同一台服务器。 对于远离网站中央托管服务器的用户,这可能会导致内容交付延迟。

CDN solves this problem by setting up multiple edge servers in different locations around the globe. These CDN servers cache static content from your site’s origin/central server, store, and present them to the users after they request for it.

CDN通过在全球不同位置设置多个边缘服务器来解决此问题。 这些CDN服务器从站点的原始服务器/中央服务器缓存静态内容,进行存储,并在用户请求后将其呈现给用户。

如何在WordPress中设置CloudFlare Free CDN_第2张图片

When there is a user request, the CDN server closest from the user’s location will handle it. For example, if someone in the USA wants to access a UK-hosted website, then a CDN server in the USA will serve that request, not the main sever in the UK.

当有用户请求时,距离用户位置最近的CDN服务器将对其进行处理。 例如,如果美国某人想要访问英国托管的网站,则美国的CDN服务器将满足该请求,而不是英国的主要服务器。

With CDN, all the user requests are handled by the nearest CDN servers. This mitigates the physical distance between the visitors and your website’s server. As a result, your website loads faster for all users regardless of their geographic location.

使用CDN,所有用户请求都由最近的CDN服务器处理。 这可以减轻访问者与您网站服务器之间的物理距离。 因此,无论用户身在何处,您的网站都能更快地加载。

A faster website also improves user experience and gives your website a slight boost in SEO rankings.

更快的网站还可以改善用户体验,并使您的网站的SEO排名略有提高。

Using a CDN also reduces the load on your primary server and protects it from crashing during traffic spikes. If you want to learn more, see our guide on why you need a CDN for your WordPress blog.

使用CDN还可以减少主服务器上的负载,并防止其在流量高峰期间崩溃。 如果您想了解更多信息,请参阅我们的指南, 了解为什么您的WordPress博客需要CDN 。

什么是Cloudflare CDN? (What Is Cloudflare CDN?)

如何在WordPress中设置CloudFlare Free CDN_第3张图片

Cloudflare is the most popular free CDN provider available on the internet. It is a large network of globally distributed servers which automatically cache static content and deliver dynamic content swiftly.

Cloudflare是互联网上最受欢迎的免费CDN提供程序。 这是一个由全球分布的服务器组成的大型网络,可自动缓存静态内容并快速交付动态内容。

On top of a CDN service, Cloudflare is also a cloud-based website firewall and a distributed proxy server. It monitors all incoming traffic to your website and blocks suspicious traffic even before it reaches your server.

除了CDN服务之外,Cloudflare还是基于云的网站防火墙和分布式代理服务器。 它监视所有流入您网站的流量,并在可疑流量到达服务器之前将其阻止。

They offer a free basic plan that’s suitable for small business websites and blogs. They also offer paid plans starting at $20 per month.

他们提供了适用于小型企业网站和博客的免费基本计划。 他们还提供每月20美元起的付费计划。

Cloudflare is an excellent choice for small businesses looking for a free CDN. However, if you want to fully utilize all Cloudflare features, then you will need the Business plan which costs $200 / month.

对于需要免费CDN的小型企业来说,Cloudflare是一个绝佳的选择。 但是,如果您想充分利用Cloudflare的所有功能,则需要每月花费200美元的业务计划。

Editor’s note: We do not use Cloudflare on WPBeginner. Instead we use MaxCDN (now part of StackPath) for our CDN service. They do not force you to use their DNS and offer more reasonable pricing at scale.

编者注:我们不在WPBeginner上使用Cloudflare。 相反,我们使用MaxCDN (现StackPath的一部分),为我们的CDN服务。 他们不会强迫您使用他们的DNS,并且会提供更合理的大规模定价。

MaxCDN与Cloudflare –有什么区别? (MaxCDN vs. Cloudflare – What’s the Difference?)

MaxCDN and Cloudflare are both quite different services actually. While MaxCDN is focused on serving your content through their CDN, Cloudflare is more focused on security and spam control.

实际上, MaxCDN和Cloudflare都是完全不同的服务。 虽然MaxCDN专注于通过其CDN提供内容,但Cloudflare更加专注于安全性和垃圾邮件控制。

They both use different technologies to serve content through their networks. MaxCDN serves content from your website’s DNS using pullzones, simply put they mirror your website. Cloudflare, on the other hand, serves content through their own DNS, and you are asked to change your website’s DNS to point to their servers.

他们俩都通过网络使用不同的技术来提供内容。 MaxCDN提供使用pullzones您的网站的DNS内容,简单地把他们反映你的网站。 另一方面,Cloudflare通过自己的DNS提供内容,并且要求您更改网站的DNS以指向其服务器。

Cloudflare acts as a proxy between you and your website’s visitors, which means you give up a lot of control. Whereas MaxCDN acts as a reverse proxy, which means you have all the control.

Cloudflare充当您和您网站访问者之间的代理,这意味着您放弃了很多控制权。 MaxCDN充当反向代理,这意味着您拥有所有控制权。

Cloudflare is better at optimizing your page speeds by preventing your site from malicious bots, attackers, and suspicious crawlers. MaxCDN is better at improving your website speed by serving your static content through their servers located around the world.

Cloudflare可以通过阻止您的网站免受恶意机器人,攻击者和可疑爬网程序的攻击,从而更好地优化页面速度。 MaxCDN通过通过遍布全球的服务器提供静态内容,可以更好地提高网站速度。

Cons of Using Cloudflare

使用Cloudflare的缺点

The biggest user complaint with Cloudflare is that while it speeds up your website, sometimes it will add a second loading screen for security verification purposes which defeats the purpose of speed because users often have to wait 5 seconds before they can see your website.

用户对Cloudflare的最大抱怨是,虽然它可以加快网站速度,但有时会出于安全验证目的而添加第二个加载屏幕,这违背了速度的目的,因为用户通常必须等待5秒钟才能看到您的网站。

Sometimes it can also display a CAPTCHA page asking users to prove that they are human. This creates a bad experience for first-time visitors who may never revisit the site.

有时,它还会显示一个CAPTCHA页面,要求用户证明他们是人类。 这给从未访问过该站点的首次访问者带来了糟糕的体验。

在WordPress网站上设置Cloudflare (Setting Up Cloudflare on Your WordPress Site)

Setting up Cloudflare on a WordPress site is quite easy. There are two different methods:

在WordPress网站上设置Cloudflare非常容易。 有两种不同的方法:

  1. By using a single-click Cloudflare setup option in your host’s control panel

    通过使用主机控制面板中的单击Cloudflare设置选项
  2. By signing up manually on Cloudflare website

    通过在Cloudflare网站上手动注册

The first method is the easiest way to enable Cloudflare CDN on your WordPress blog. Some of the top WordPress hosting services like SiteGround have partnered with Cloudflare to offer an easy setup option through their control panel.

第一种方法是在WordPress博客上启用Cloudflare CDN的最简单方法。 一些顶级WordPress托管服务(例如SiteGround)已与Cloudflare合作,以通过其控制面板提供简单的设置选项。

If your web host doesn’t offer a built-in Cloudflare setup option, then you can manually add the service on your site. We will show both of these methods in details below.

如果您的网络托管服务商不提供内置的Cloudflare设置选项,则可以在您的网站上手动添加该服务。 我们将在下面详细介绍这两种方法。

方法1:使用cPanel中的一键安装选项设置Cloudflare CDN (Method 1: Setting up Cloudflare CDN with One-Click Setup Option in cPanel)

As we mentioned earlier that some WordPress hosting providers like SiteGround offer an easy option to configure Cloudflare CDN in WordPress.

如前所述,一些WordPress托管提供商(例如SiteGround)提供了一个简单的选项,可以在WordPress中配置Cloudflare CDN。

These web hosts provide a built-in Cloudflare integration app in your hosting cPanel to enable the service with just a few clicks.

这些虚拟主机在托管cPanel中提供了内置的Cloudflare集成应用程序,只需单击几下即可启用该服务。

This Cloudflare setup option works similarly with most hosting providers that have the integration. For your reference, we will show the setup process on SiteGround hosting.

此Cloudflare设置选项与大多数具有集成功能的托管服务提供商类似地工作。 供您参考,我们将显示SiteGround托管上的设置过程。

Enabling Cloudflare CDN on SiteGround

在SiteGround上启用Cloudflare CDN

If you are using SiteGround as your WordPress hosting company, then you can set up Cloudflare CDN on your site in just a few minutes.

如果您将SiteGround用作WordPress托管公司,则只需几分钟即可在您的站点上设置Cloudflare CDN。

To get started, login to your cPanel and navigate to the ‘Site Improvement Tools’ section. After that, click on the ‘Cloudflare’ icon.

首先,请登录您的cPanel并导航至“网站改进工具”部分。 之后,点击“ Cloudflare”图标。

SiteGround recently started switching to a new control panel. If you’re using the new panel, then you’ll see Cloudflare listed under Speed tab. For example, take a look at the screenshot below.

SiteGround最近开始切换到新的控制面板。 如果您使用的是新面板,则将在“速度”选项卡下看到Cloudflare。 例如,看下面的截图。

To enable Cloudflare free CDN on your website, just click on the ‘Set Up’ button to continue.

要在您的网站上启用免费的Cloudflare CDN,只需单击“设置”按钮以继续。

After that, you will see a popup asking you to create a Cloudflare account or connect to your existing one.

之后,您将看到一个弹出窗口,要求您创建一个Cloudflare帐户或连接到现有帐户。

如何在WordPress中设置CloudFlare Free CDN_第4张图片

Next, you will see a message indicating that the CDN activation is in progress. Once it is complete, the Cloudflare CDN will be active on your WordPress site.

接下来,您将看到一条消息,指示CDN激活正在进行中。 完成后,Cloudflare CDN将在您的WordPress网站上处于活动状态。

方法2:在WordPress中手动设置Cloudflare CDN (Method 2: Setting up Cloudflare CDN in WordPress Manually)

If your web hosting doesn’t have a single click Cloudflare configuration option, then you can use this method. It can take a few more minutes, but it is also easy and user-friendly.

如果您的虚拟主机没有单击Cloudflare配置选项,则可以使用此方法。 这可能需要几分钟,但它也很容易且用户友好。

To begin, you need to visit CloudFlare website and click on the ‘Sign Up’ button.

首先,您需要访问CloudFlare网站,然后单击“注册”按钮。

On the next page, you need to enter your email address and password to create a Cloudflare account. Simply enter the information required, and then click on the ‘Create Account’ button.

在下一页上,您需要输入电子邮件地址和密码来创建Cloudflare帐户。 只需输入所需的信息,然后单击“创建帐户”按钮。

After that, you need to enter your website’s URL.

之后,您需要输入网站的URL。

如何在WordPress中设置CloudFlare Free CDN_第5张图片

On the next screen, you will be asked to choose a plan. For the sake of this tutorial, we will select a free plan.

在下一个屏幕上,将要求您选择一个计划。 为了本教程的缘故,我们将选择一个免费计划。

如何在WordPress中设置CloudFlare Free CDN_第6张图片

After that, Cloudflare will show you a list of all DNS records their systems found. This will include your subdomains as well.

之后,Cloudflare将向您显示其系统找到的所有DNS记录的列表。 这也将包括您的子域。

The DNS records you want to be passed through Cloudflare will have orange cloud icon. The DNS records that will bypass Cloudflare will have a gray cloud icon.

您要通过Cloudflare传递的DNS记录将带有橙色的云图标。 绕过Cloudflare的DNS记录将带有灰色的云图标。

You need to review the list to make sure that your primary domain is active on Cloudflare with an orange cloud icon.

您需要查看列表,以确保您的主域在Cloudflare上处于活动状态且带有橙色云图标。

如何在WordPress中设置CloudFlare Free CDN_第7张图片

Once you verify your DNS records, click on the Continue option at the bottom.

验证DNS记录后,单击底部的继续选项。

On the next and the final step of your setup, Cloudflare will ask you to update your nameservers. You will be asked to change your name servers and point them to Cloudflare nameservers.

在设置的下一步也是最后一步,Cloudflare将要求您更新名称服务器。 系统将要求您更改名称服务器并将其指向Cloudflare名称服务器。

如何在WordPress中设置CloudFlare Free CDN_第8张图片

Notice: Changing name server can take some time to propagate through all over the internet. During this time, your website may become inaccessible for some users.

注意:更改名称服务器可能需要一些时间才能在整个Internet上传播。 在此期间,某些用户可能无法访问您的网站。

You can change name servers either from your domain registrar account like Domain.com, or if you got a free domain from your web hosting provider like Bluehost, then you will have to change the name server by logging into your hosting account.

您可以从域名注册商帐户(如Domain.com)更改名称服务器,也可以从网络托管服务提供商(如Bluehost)获得免费域名 ,则必须登录到托管帐户来更改名称服务器。

For the sake of this tutorial, we will be showing you how to change the name servers from the Bluehost control panel. While the process is similar across hosting companies, you can always ask your hosting provider for detailed instructions for their control panel.

在本教程中,我们将向您展示如何从Bluehost控制面板更改名称服务器。 尽管整个托管公司的过程相似,但是您始终可以向托管提供商咨询其控制面板的详细说明。

Once you are logged on to your Bluehost cPanel dashboard, go to ‘Domains’ section, and select your domain name. After that, click on the ‘Name Servers’ tab and ‘Edit’ option.

登录到Bluehost cPanel仪表盘后 ,转到“域”部分,然后选择您的域名。 之后,单击“名称服务器”选项卡和“编辑”选项。

Next, you need to select ‘Custom’ and enter the nameservers provided by Cloudflare.

接下来,您需要选择“自定义”并输入Cloudflare提供的名称服务器。

如何在WordPress中设置CloudFlare Free CDN_第9张图片

After that, you need to go back to Cloudflare setup page, and click on ‘Done, check nameservers’ button to finish the setup.

之后,您需要返回Cloudflare设置页面,然后单击“完成,检查名称服务器”按钮以完成设置。

如何在WordPress中设置CloudFlare Free CDN_第10张图片

That’s it! Now it will take a few minutes to update your domain nameservers and activate Cloudflare.

而已! 现在,将需要几分钟来更新您的域名服务器并激活Cloudflare。

Once activated, you will see the success message on your Cloudflare dashboard.

激活后,您将在Cloudflare仪表板上看到成功消息。

如何在WordPress中设置CloudFlare Free CDN_第11张图片

You can now customize your Cloudflare settings from this dashboard. We will show you the most critical settings in the next section.

现在,您可以从此仪表板自定义Cloudflare设置。 在下一部分中,我们将向您显示最关键的设置。

Note: The above screenshots show Bluehost control panel. Your nameserver settings may look different if you’re using a different hosting provider.

注意 :以上屏幕截图显示了Bluehost控制面板。 如果您使用其他托管服务提供商,则您的域名服务器设置可能看起来有所不同。

配置最重要的Cloudflare设置 (Configuring Most Important Cloudflare Settings)

Your basic Cloudflare set up is complete, but there are a few essential settings you need to configure to keep your WordPress site secure.

基本的Cloudflare设置已完成,但需要配置一些基本设置以确保WordPress网站的安全。

1. Configure WordPress Specific Page Rules

1.配置WordPress特定页面规则

By setting up page rules, you can customize how Cloudflare works on specific pages on your site. It is especially useful in securing critical pages like login page, wp-admin area, etc.

通过设置页面规则,您可以自定义Cloudflare在网站上特定页面上的工作方式。 在保护关键页面(如登录页面,wp-admin区域等)方面特别有用。

Cloudflare free account allows you to set up three page-rules. If you want to add more page rules, then you need to pay $5 per month for five additional rules.

Cloudflare免费帐户允许您设置三个页面规则。 如果您想添加更多页面规则,则需要每月为5条其他规则支付5美元。

First, you need to click on the Page Rules option at the top and then click on the Create Page Rule button.

首先,您需要单击顶部的“页面规则”选项,然后单击“创建页面规则”按钮。

如何在WordPress中设置CloudFlare Free CDN_第12张图片

After that, you can set up the following three page-rules.

之后,您可以设置以下三个页面规则。

a) Secure your WordPress login page

a)保护您的WordPress登录页面

Page URL: example.com/wp-login.php*
Setting: Security Level; High

页面网址:example.com/wp-login.php*
设置:安全级别; 高

如何在WordPress中设置CloudFlare Free CDN_第13张图片

b) Exclude WordPress Dashboard from Cloudflare and Enable High Security

b)从Cloudflare中排除WordPress仪表板并启用高安全性

Page URL: example.com/wp-admin*
Settings: Security Level; High
Cache Level; Bypass
Disable Performance
Disable Apps

网页网址:example.com/wp-admin*
设置:安全级别; 高
缓存级别; 旁路
禁用性能
禁用应用

如何在WordPress中设置CloudFlare Free CDN_第14张图片

c) Force HTTPS

c)强制HTTPS

Page URL: http://*example.com/*
Setting: Always use HTTPS

网页网址:http://*example.com/*
设置:始终使用HTTPS

如何在WordPress中设置CloudFlare Free CDN_第15张图片

2. Configure SSL Certificate Settings

2.配置SSL证书设置

Another important setting is the SSL certificate available in the ‘SSL/TSL’ menu at the top.

另一个重要设置是顶部“ SSL / TSL”菜单中的SSL证书。

Make sure to choose ‘Full’ if you are already using SSL.

如果您已经在使用SSL,请确保选择“完整”。

If you don’t have an SSL certificate, then see our guide on how to get a free SSL certificate for your website.

如果您没有SSL证书,请参阅我们的指南, 了解如何为您的网站获取免费的SSL证书 。

Once done, Cloudflare will provide a coveted green padlock to signify that your website is secure.

完成后,Cloudflare将提供令人垂涎的绿色挂锁,以表示您的网站是安全的。

使用插件为WordPress优化Cloudflare (Optimizing Cloudflare for WordPress Using a Plugin)

Cloudflare offers a dedicated WordPress plugin for one-click WordPress-optimized settings. The plugin lets you quickly set up Cloudflare on your WordPress site, add web application firewall (WAF) rulesets, automatically purge the cache, and more.

Cloudflare为一键式WordPress优化设置提供了专用的WordPress插件。 该插件可让您在WordPress网站上快速设置Cloudflare,添加Web应用程序防火墙(WAF)规则集,自动清除缓存等。

To get started, install and activate the Cloudflare plugin on your website. For more details, see our step by step guide on how to install a WordPress plugin.

首先,请在您的网站上安装并激活Cloudflare插件 。 有关更多详细信息,请参阅有关如何安装WordPress插件的分步指南。

Once done, you need to visit Settings » Cloudflare from your admin panel to configure Cloudflare settings.

完成后,您需要从管理面板访问设置»Cloudflare ,以配置Cloudflare设置。

On the settings page, you will see a Create Your Free Account button and Sign-in option for already existing accounts. Simply click on the sign-in option.

在设置页面上,您将看到一个“创建免费帐户”按钮和已存在帐户的登录选项。 只需单击登录选项。

如何在WordPress中设置CloudFlare Free CDN_第16张图片

On the next screen, you will need to enter your Cloudflare email and API key.

在下一个屏幕上,您将需要输入Cloudflare电子邮件和API密钥。

You can find your API key in your account area on the Cloudflare website.

您可以在Cloudflare网站上的帐户区域中找到API密钥。

Simply open the ‘My Profile’ page and then click on the API tokens. After that, go to the Global API Key section and click on the View button.

只需打开“我的资料”页面,然后单击API令牌。 之后,转到“全局API密钥”部分,然后单击“查看”按钮。

This will open a popup and display your API key. You need to copy the key.

这将打开一个弹出窗口并显示您的API密钥。 您需要复制密钥。

Next, come back to your WordPress dashboard and enter your email address and API key.

接下来,返回到WordPress仪表板,然后输入您的电子邮件地址和API密钥。

如何在WordPress中设置CloudFlare Free CDN_第17张图片

After that, Cloudflare home page will appear on your dashboard. From there, you can apply a single-click WordPress optimization, purge cache, enable automatic cache, etc.

之后,Cloudflare主页将出现在您的仪表板上。 从那里,您可以单击WordPress优化,清除缓存,启用自动缓存等。

如何在WordPress中设置CloudFlare Free CDN_第18张图片

You can find more Cloudflare options by clicking on the Settings option.

您可以通过单击设置选项找到更多Cloudflare选项。

如何在WordPress中设置CloudFlare Free CDN_第19张图片

It also shows stats such as visitors, bandwidth saved, threats blocked, etc. from the Analytics option.

它还通过“分析”选项显示统计信息,例如访问者,节省的带宽,阻止的威胁等。

We hope this article helped you to learn how to set up Cloudflare free CDN in WordPress. You may also want to see our complete WordPress website security guide.

我们希望本文能帮助您学习如何在WordPress中设置Cloudflare免费CDN。 您可能还想查看我们完整的WordPress网站安全指南 。

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

如果您喜欢这篇文章,请订阅我们的YouTube频道 WordPress视频教程。 您也可以在Twitter和Facebook上找到我们。

翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-setup-cloudflare-free-cdn-in-wordpress/

你可能感兴趣的:(网络,java,安全,python,wordpress)