免费 SSL 证书 certbot 配置
certbot 链接地址
AWS ec2 配置免费证书
# aws 参考链接:https://docs.amazonaws.cn/AWSEC2/latest/UserGuide/SSL-on-amazon-linux-2.html # 首先安装epel源,epel源中包含certbot # ec2 sudo amazon-linux-extras install epel # centos7 yum install epel-release # 安装certbot yum install certbot python2-certbot-nginx # 签发证书 certbot --agree-tos certonly --email mr.liulei@qq.com --webroot -w /data/tls/ -d vaultuid.ll2019.cn -d www.ll2019.cn 备注: --agree-tos 同意用户协议 --email 首次申请证书时,需要邮箱地址来创建 Let's Encrypt 的账号。不过,并不会验证此账号。邮箱地址用于接受证书过期提醒。 --certonly 只申请证书 --webroot 通过在当前运行的 web 服务器下存放验证文件来验证身份。 -w 指定web服务器的根目录 -d 指定要申请证书的域名 # 生成证书的目录中几个文件的内容 cert.pem: 网站自身的证书; chain.pem: 网站证书链中的上级证书; fullchain.pem: 包含了网站自身证书和上级证书的完整证书链; privkey.pem: 网站自身证书对应的私钥。
nginx自动配置证书
1 # 自动配置域名证书 2 # 一键配置 3 sudo certbot --nginx 4 or 5 # 只获取证书手动来配置nginx 6 sudo certbot certonly --nginx 7 8 回车后输入域名, 9 10 # 域名自动续期 11 echo "0 0,12 * * * python -c 'import random; import time; time.sleep(random.random() * 3600)' && certbot renew -q" | sudo tee -a /etc/crontab > /dev/null
⚠️:自动配置nginx ssl 证书需要在nginx中配置443端口和域名,如下:
1 server { 2 listen 443; 3 server_name xxxx.cn; 4 # ssl_certificate /etc/letsencrypt/live/xxxx.cn/fullchain.pem; # managed by Certbot 5 # ssl_certificate_key /etc/letsencrypt/live/xxxx.cn/privkey.pem; # managed by Certbot 6 access_log /var/log/nginx/jenkins_access_log main; 7 #error_log /var/log/nginx/jenkins_error_log main; 8 client_max_body_size 60M; 9 client_body_buffer_size 512k; 10 location / { 11 proxy_pass http://localhost:8080/; 12 proxy_redirect off; 13 proxy_set_header Host $host; 14 proxy_set_header X-Real-IP $remote_addr; 15 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 16 } 17 }
# 域名证书部分不需要写,他会自动补全ssl证书,补全之后如上注释部分;
本文来自博客园, 作者:Star-Hitian, 转载请注明原文链接:https://www.cnblogs.com/Star-Haitian/p/14971985.html