certbot使用cloudflare的api签发ssl

先去cloudflare上申请IP https://dash.cloudflare.com/profile/api-tokens

在Edit zone DNS的模版下授权可以修改DNS的域名

写入API配置

echo " dns_cloudflare_api_token = XXXXXXXXXXXXXXXXXXXXXx" >/root/cloudflare.ini

安装和签发ssl

dnf install -y epel-release
dnf install -y certbot certbot-dns-cloudflare python*-certbot-dns-cloudflare
certbot certonly --agree-tos --email [email protected]  --dns-cloudflare --dns-cloudflare-credentials /root/cloudflare.ini -d kvm.la

使用cloudflare后nginx传递客户端真实ip

主要两个地方注意一下, cloudflare会传送一个CF-Connecting-IP的header参数为访客的真实ip,所以  read_ip读取它.

然后设定REMOTE_ADDR读取IP, 可以从FORWARDED也可以用CF-Connecting-IP参数

set_real_ip_from 103.21.244.0/22;
set_real_ip_from 103.22.200.0/22;
set_real_ip_from 103.31.4.0/22;
set_real_ip_from 104.16.0.0/12;
set_real_ip_from 108.162.192.0/18;
set_real_ip_from 131.0.72.0/22;
set_real_ip_from 141.101.64.0/18;
set_real_ip_from 162.158.0.0/15;
set_real_ip_from 172.64.0.0/13;
set_real_ip_from 173.245.48.0/20;
set_real_ip_from 188.114.96.0/20;
set_real_ip_from 190.93.240.0/20;
set_real_ip_from 197.234.240.0/22;
set_real_ip_from 198.41.128.0/17;
real_ip_header CF-Connecting-IP;
proxy_set_header REMOTE_ADDR $HTTP_X_FORWARDED_FOR;