AWS CloudFront(AWS CDN)设置、使用教程;为WordPress加速

因网络知识浅薄,若有错漏,麻烦不吝指正。

一、 CloudFront简单介绍

Amazon CloudFront,即AWS CDN,节点分布全球,亚洲国内、日本、香港、新加坡等,除国内节点需要备案,其他均不需要。
首年免费,每月送50GB流量。流量只计算出流量,入流量不计。

CloudFront官网:https://aws.amazon.com/cn/cloudfront/

二、 CloudFront的注册

CloudFront有中文页面,注册需要手机、信用卡验证。

三、 CloudFront的申请、设置

以tg.tn为例(在主机处,同时绑定tg.tn和www.tg.tn,访问主域名为tg.tn

进入AWS CloudFront后台,点击 Create Distribution
AWS CloudFront(AWS CDN)设置、使用教程;为WordPress加速
选择 WEB 加速
AWS CloudFront(AWS CDN)设置、使用教程;为WordPress加速
Origin Domain Name:只能是域名,www.tg.tn
Origin Protocol Policy:如果安全性重要,就用https
Query String Forwarding and Caching:选择全部缓存
Compress Objects Automatically:选YES
AWS CloudFront(AWS CDN)设置、使用教程;为WordPress加速
AWS CloudFront(AWS CDN)设置、使用教程;为WordPress加速
申请/导入域名SSL证书:https://console.aws.amazon.com/acm/home?region=us-east-1#/
AWS SSL证书申请,安装说明一步一步,非常简单。
导入证书的话,选择Apache格式的。

这就是创建好的。选择 ID 进入CDN管理,选择EDIT
AWS CloudFront(AWS CDN)设置、使用教程;为WordPress加速

AWS CloudFront(AWS CDN)设置、使用教程;为WordPress加速

Alternate Domain Names(CNAMEs):填写要加速的域名
SSL Certificate:可以用AWS的(免费),也可以用自己的SSL证书(免费)
AWS CloudFront(AWS CDN)设置、使用教程;为WordPress加速
三、DNS解析设置

在自己的域名解析处设置(建议国内DNSPOD、DNS.COM、华为云DNS等)

www.tg.tn 全网解析 A记录 为你的主机IP(解析源)

tg.tn 国内解析 cname 为 xxx.cloudfront.net(cloudfront给的加速域名)
www.tg.tn 国内解析 cname 为 xxx.cloudfront.net(cloudfront给的加速域名)
AWS CloudFront(AWS CDN)设置、使用教程;为WordPress加速

AWS CloudFront(AWS CDN)设置、使用教程;为WordPress加速
四、设置AWS CloudFront()为WordPress加速

WordPress,因为需要登陆、评论等,因此需要对其他部分进行设置。类似需要登陆、评论的程序,均需要设置。

进入你的AWS CloudFront设置页面,点击 Behaviors,编辑默认规则
AWS CloudFront(AWS CDN)设置、使用教程;为WordPress加速
Viewer Protocol Policy:建议HTTPS only,也可Redirect HTTP to HTTPS
Allowed HTTP Methods:选 GET, HEAD, OPTIONS, PUT, POST, PATCH, DELETE
Cached HTTP Methods:选择 OPTIONS
Cache Based on Selected Request Headers:选择 Whitelist
Whitelist Headers:下拉,添加 Host、Origin
AWS CloudFront(AWS CDN)设置、使用教程;为WordPress加速
然后创建新Behaviors

Path Pattern:/wp-login.php
Forward Cookies:选择 Whitelist
Whitelist Cookies:添加如下
comment_author_*
comment_author_email_*
comment_author_url_*
wordpress_*
wordpress_logged_in_*
wordpress_sec_*
wordpress_test_cookie
wp-settings-*
AWS CloudFront(AWS CDN)设置、使用教程;为WordPress加速

AWS CloudFront(AWS CDN)设置、使用教程;为WordPress加速
继续创建新Behaviors
Path Pattern:/wp-admin/*
AWS CloudFront(AWS CDN)设置、使用教程;为WordPress加速

AWS CloudFront(AWS CDN)设置、使用教程;为WordPress加速
继续创建新Behaviors
Path Pattern:/wp-json/*
AWS CloudFront(AWS CDN)设置、使用教程;为WordPress加速

AWS CloudFront(AWS CDN)设置、使用教程;为WordPress加速
参考:https://jeffreyeverhart.com/2018/12/07/setup-aws-cloudfront-for-wordpress-scaling-this-blog/,并得到SaltyFishTech老板的热心指导。

未经允许不得转载:吾爱主机之家 » AWS CloudFront(AWS CDN)设置、使用教程;为WordPress加速