云 flare Workers提供了一个无服务器执行环境,使您无需配置或维护基础架构即可创建全新的应用程序或扩充现有的应用程序。 您的服务工作者将拦截发往您域的所有HTTP请求,并可以返回任何有效的HTTP响应。您的工作人员可以向公共Internet上的任何服务器发出传出的HTTP请求。
在这篇文章中,我列出了Cloudflare Workers如何帮助我实现想法的一些用法。 至少在开始创建Cloudflare Workers之前,您需要创建一个免费的Cloudflare帐户。如果您自己的域与Cloudflare集成,它将更好地工作。
- 托管无服务器静态网页
- 为您的工人使用自己的域名
托管无服务器静态网页
返回HTML示例页面: //developers.cloudflare.com/workers/examples
3 保存并部署示例应用
4 使用所见即所得HTML编辑器获取HTML代码
我使用了Blogger HTML编辑器来创建页面,然后将其切换到HTML视图以获取代码。然后将其复制回之间的Workers应用代码区域<body> and </body>
为您的工人使用自己的域名
1 创建一个 sub-domain name
51sec,org
必须托管在CloudFlare上或指向CloudFlare,其他DNS注册商将导致各种奇怪的错误。Proxied.
2 域名与工作人员相关
Workers
switch to your domain's Workers
域名标签(请注意,域名在此处, in Workers you won't find a place to associate it with your domain
然后将关联添加到 Add route
3 创建一个 Workers Route
Route
fills in the subdomain with /*
,(proxy.51sec.org/*),Worker
selects the worker application we created before,
需要自定义域名访问权限的人, 因此,您需要创建一个Worker,然后关联,以表示对 Worker
通过此自定义域名提供的服务:proxy.51sec.org/*完成后,您可以访问 Worker
通过自定义域名提供服务,例如 //
proxy.51sec.org/
设置DDNS的API
云 Flare DDNS
云 Flare本身没有官方的DDNS支持,但是可以使用CloudFlare API来实现。 GitHub Project 云 flare-ddns 提供了一个不错的脚本,可以使用API更新您的CloudFlare DNS IP。我已将其分叉到我的存储库中使用。
示例:Ubuntu 18.04
Sudo -i
apt-get update -y & apt-get upgrade -y
git clone //github.com/51sec/cloudflare-ddns.git
输入目录
cd cloudflare-ddns/
安装提示
apt-get install python-pip
pip install -r requirements.txt
重命名config.yaml.template文件
mv config.yaml.template config.yaml
修改config.yaml
nano config.yaml
几乎是这样的:
%YAML 1.2
# 云 Flare DDNS updater script config.
---
# 云 Flare API key
# You can find this under Account > My account after logging into 云 Flare.
cf_key: 'cloudflare API Key'
# Email address for your 云 Flare account.
cf_email: 'CloudFlare log in email'
# Domain you're using 云 Flare to manage.
# If the host name you're updating is "ddns.domain.com", make this "domain.com".
cf_domain: 'root domain'
# The subdomain you're using for your DDNS A record.
# If the host name you're updating is "ddns.domain.com", make this "ddns".
# However, if you're updating the A record for the naked domain (that is, just
# "domain.com" without a subdomain), then set cf_subdomain to an empty value.
cf_subdomain: 'sub domain'
# 云 Flare service mode. This enables/disables CF's traffic acceleration.
# Enabled (orange cloud) is 1. Disabled (grey cloud) is 0.
cf_service_mode: 0
# If set to true, prints a message 上 ly when the record changes or when
# there's an error. If set to 'false', prints a message every time even if
# the record didn't change.
quiet: false
# If set to true then we call the ec2metadata service for the instance
# public ip address rather than an external service.
aws_use_ec2metadata: false
# If set to true dig will be used to fetch the public IP which is better
# but not available 上 all systems.
use_dig: false
获取API密钥
创建子域
运行脚本
python cloudflare_ddns.py config.yaml
添加计划任务
crontab -e
填写以下内容
# Every 15 minutes, check the current public IP, and update the A record 上 云 Flare.
*/15 * * * * /root/cloudflare-ddns/cloudflare_ddns.py /root/cloudflare-ddns/config.yaml >> /var/log/cloudflare_ddns.log
计划的作业配置完成后,IP将每15分钟更新到Cloudflare
来自Blogger //blog.fabiandinkins.com/2020/12/cloudflare-workers-and-api-usage.html