cloudflare 的 page rules 设置

本文介绍 URL pattern 的匹配规则及其在 Cloudflare 中的应用,包括如何使用 * 通配符来匹配 URL,并解释了不同缓存策略的作用,如 Basic Caching、Aggressive caching 等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

URL pattern url 匹配规则:支持 * (可以代表 0 个或多个 字符)

*example.com/+

能匹配:

  • http://example.com/+
  • http://www.example.com/+
  • https://www.example.com/+
  • https://blog.example.com/+
  • https://www.blog.example.com/+
不能匹配:

  • http://www.example.com/blog/+ 
  • http://www.example.com+
===========

Forwarding: 处于 ON 的话,表示匹配上面规则的URL会被转向到设置的URL:

*example.com/+*

可以在目标URL里用 $1 表示第一个 * 位置表示的字符串  $2 表示第二个 * 位置

http://blog.cloudflare.com/introducing-pagerules-url-forwarding


===========

处于OFF的话,匹配规则的URL会按照下面的选项进行处理。

比较重要的一个设置是 Custom caching

Bypass cache:Will not cache at all   匹配规则的URL不被缓存

Basic Caching: 缓存那些默认的文件后缀的文件

Aggressive caching: Caches all static content that has a query string in it    缓存带 ? 的URL的内容,不同的 query string 会缓存成不同的文件

  比如 xxx.com/page.php?lp=11  缓存后,访问 xxx.com/page.php?lp=22 就会连到真实网站下载网页内容,来进行缓存。

Ignore query string:Caches static content that has a query string and treats it as one file   缓存带 ? 的URL的内容, 忽略 query string,不同的query string都是对应同一个缓存文件

  比如 xxx.com/page.php?lp=11  缓存后,访问 xxx.com/page.php?lp=22 就不会连到真实网站,而是直接把缓存服务器上的文件内容返回给浏览器。

Cache everything:Caches all file types on your site, including static content and HTML.  缓存所有的内容


http://blog.cloudflare.com/introducing-pagerules-advanced-caching

http://support.cloudflare.com/kb/page-rules/what-do-the-custom-caching-options-mean-in-the-url-editor


### Cloudflare CDN 使用指南 #### 创建并设置Cloudflare账户 为了使用Cloudflare的内容分发网络(CDN),需先创建一个账号。登录到官网后,输入域名信息以便让Cloudflare接管DNS管理。一旦完成此过程,网站流量会通过Cloudflare服务器传递,自动启用基本的安全性和性能优化功能[^1]。 #### 配置页面规则(Page Rules) 对于特定URL路径应用自定义缓存行为和其他设置非常有用。例如可以指定某些文件夹下的资源总是被缓存或是永远不被缓存。这有助于更精细地控制哪些数据应该存储在网络边缘位置上以加速访问速度[^2]。 #### 启用SSL/TLS加密连接 安全套接字层(SSL)/传输层安全性(TLS)证书能够确保客户端与服务器之间的通信是经过加密保护的。在Cloudflare仪表板内轻松开启该选项,并选择适合业务需求的日志级别以及HTTPS重定向策略来增强站点防护措施[^3]。 #### 调整缓存级别(Caching Level) 默认情况下,Cloudflare会对静态资产执行积极缓存;然而也可以调整全局或针对单个项目设定不同的缓存模式。“标准”意味着遵循源站响应头指示,“忽略查询字符串(Ignore Query String)”则允许即使带有参数也视为相同请求处理从而提高命中率[^4]。 ```python # Python代码示例:如何利用API获取当前激活中的Page Rule列表 import requests url = "https://api.cloudflare.com/client/v4/zones/{zone_id}/pagerules" headers = { 'X-Auth-Email': '{email}', 'X-Auth-Key': '{auth_key}' } response = requests.get(url, headers=headers) if response.status_code == 200: data = response.json() rules = data['result'] for rule in rules: print(f"ID: {rule['id']}, Status: {rule['status']}") else: print("Failed to fetch page rules.") ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值