zl程序教程

您现在的位置是:首页 >  硬件

当前栏目

CDN网站防护与Worker无服务器应用构建

服务器应用网站 构建 防护 CDN Worker
2023-06-13 09:13:29 时间

[TOC]

0x00 cloudflare

前言 描述:cloudflare是一家国外的 CDN 加速服务商还是很有名气的,提供免费和付费的加速和网站保护服务。 Cloudflare是用的比较多的一个国外的NS服务商,同时还提供15年的SSL证书以及免费CDN,同时也可以防护DDoS攻击。 以前的百度云加速的国外节点就是和 cloudflare 合作使用的 cloudflare 的节点。

特点事项:

  • cloudflare 提供了不同类型的套餐,即使是免费用户cloudflare 提供的功能也是很全面的。
  • 对于访客来自于国外的网站很不错;
  • 对于访客来自于国内的网站加速效果有限,有些甚至会变慢,不过其安全防护功能也很不错。

cloudflare官网地址:https://dash.cloudflare.com/

使用步骤 邮箱注册:注册完后自动进入添加网站界面,首次登录添加网站分为四步:选择方案、添加网站域名、添加DNS记录、更新域名服务器

WeiyiGeek.CloudflareCDN

添加网站 :填入自己的主域名(不带 www 的)然后Cloudflare会扫描该域名当前的DNS记录,你可以保留/添加/删除等等

#管理您的域名系统(DNS)设置(自动扫描 DNS 记录)
CNAME weiyigeek.github.io	is an alias of weiyigeek.github.io	Automatic		
CNAME www	is an alias of weiyigeek.github.io	Automatic

WeiyiGeek.DNS解析记录

域名注册商修改NS记录即可等待生效完成即可;

# Log in to your registrar account (登录您的域名注册商,将DNS改成以下)

#Remove these nameservers:
f1g1ns2.dnspod.net
f1g1ns1.dnspod.net

#Replace with Cloudflare's nameservers:
bayan.ns.cloudflare.com
vita.ns.cloudflare.com

以腾讯云的为例:

WeiyiGeek.设置DNS服务器

验证修改配置与DNS

#方式1:在cloudflare中checknow进行验证并且发送邮件给您
Great news! Cloudflare is now protecting your site
Here are some commonly used options to review.

WeiyiGeek.

#方式2:dig与nslookup检测
dig www.weiyigeek.github.io
;; QUESTION SECTION:
;www.weiyigeek.github.io.		IN	A

;; ANSWER SECTION:
www.weiyigeek.github.io.	5	IN	A	104.18.51.99  #指向cloudflare的IP地址
www.weiyigeek.github.io.	5	IN	A	104.18.50.99

;; AUTHORITY SECTION:
weiyigeek.github.io.		5	IN	NS	bayan.ns.cloudflare.com.
weiyigeek.github.io.		5	IN	NS	vita.ns.cloudflare.com.

;; ADDITIONAL SECTION:
vita.ns.cloudflare.com.	5	IN	A	173.245.58.238
bayan.ns.cloudflare.com. 5	IN	A	173.245.59.72
bayan.ns.cloudflare.com. 5	IN	AAAA	2400:cb00:2049:1::adf5:3b48


#nslookup命令
nslookup -qt="A" www.weiyigeek.github.io
非权威应答:
名称:    www.weiyigeek.github.io
Addresses:  2606:4700:30::6812:3263
          2606:4700:30::6812:3363
          104.18.50.99  #指向cloudflare的IP地址
          104.18.51.99 
nslookup -qt="CNAME" www.weiyigeek.github.io
weiyigeek.github.io
        primary name server = bayan.ns.cloudflare.com
        responsible mail addr = dns.cloudflare.com
        serial  = 2031741885
        refresh = 10000 (2 hours 46 mins 40 secs)
        retry   = 2400 (40 mins)
        expire  = 604800 (7 days)
        default TTL = 3600 (1 hour)

#方式3:腾讯监测
https://domaintool.cloud.tencent.com/result?domain=weiyigeek.github.io

WeiyiGeek.CDN缓存配置

常用配置项

  1. 加速访问
    • Speed 选项
      • Auto Minify:选择压缩 JavaScript、CSS、HTML;
      • Rocket Loader:Automatic(自动);
    • Caching 选项
      • Caching Level:Standard(标准);
      • Browser Cache Expiration:1day;
      • Always Online:on;
    • 调试模式不使用缓存长关,在调试网站如果需要实时预览变化可以打开。 -Development Mode : off

2.安全防护

  • Firewall 选项
    • Security Level:High;
    • Challenge Passage:30 min;
    • Browser Integrity Check:on;
  • Scrape Shield 选项 Email Address Obfuscation:on Server-side Excludes:on Hotlink Protection:on
  • Caching 选项 当网站内容更新后,如果缓存期限还未到,那么更新内容并不会立即生效,就需要进入 cloudflare 后台手动刷新缓存。可以输入更新的页面只刷新该页面的缓存,也可以刷新全站的缓存。