下载letsencrypt工具 git clone https://github.com/letsencrypt/letsencrypt
到下载的目录下 cd letsencrypt/
执行下面命令,给certbot-auto 安装所需要的环境 ./letsencrypt-auto
执行下面命令生成证书,生成的过程中会需要你添加txt记录到cloudflare,添加上去就行, ./certbot-auto certonly -d xxxxxx.com -d www.xxxxxx.com --manual --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory -v
生成完之后会成/etc/letsencrypt/live/xxxxxx.com有下面一文件 cert.pem chain.pem fullchain.pem privkey.pem README 其中cert.pem是公钥 privkey.pem是私钥
nginx配置证书如下 listen 443 ssl; ssl_certificate /etc/letsencrypt/live/xxxxxx.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/xxxxxx.com/privkey.pem;
apache里面的配置如下 <VirtualHost *:443> DocumentRoot "xxxxxx/xxx/xxx" ServerName www.xxxxxx.com ServerAlias xxxxxx.com SSLEngine on SSLProtocol all -sslv2 SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5 SSLCertificateFile "/etc/letsencrypt/live/xxxxxx.com/cert.pem" SSLCertificateKeyFile "/etc/letsencrypt/live/xxxxxx.com/privkey.pem" <FilesMatch ".(cgi|shtml|phtml|php)$"> SSLOptions +StdEnvVars </FilesMatch> <Directory "xxxxxx/xxx/xxx"> AllowOverride All SSLOptions +StdEnvVars </Directory> </VirtualHost>