栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

阿里云服务器 Certbot 申请 LetsEncrypt 泛域名免费证书

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

阿里云服务器 Certbot 申请 LetsEncrypt 泛域名免费证书

阿里云服务器 Certbot 申请 LetsEncrypt 泛域名免费证书 准备工作

首先,要有一个域名,且使用 阿里云DNS 提供解析服务。系统Centos 7.6以上
查看系统版本命令:lsb_release -a

其次,要在阿里云 https://ram.console.aliyun.com/ 创建一个子账号并配置 RAM 权限 AliyunDNSFullAccess,并为子账号生成AccessKey用于通过API管理DNS解析。

1.安装Python

这里我使用了 Python 虚拟环境的方式安装 Certbot,这样的好处是 pip 安装任何依赖包不会对当前系统造成任何影响

yum install python36 -y
2.配置环境(一步一步执行)
mkdir -p /opt/soft/tool/certbot/
cd /opt/soft/tool/certbot/
python3 -m venv venv
source venv/bin/activate
3.安装certbot-nginx
pip install certbot certbot-nginx certbot-dns-aliyun

下列错误解决 执行:pip install --upgrade pip 后再执行步骤3

遇到下列问题忽略,输入你的邮箱即可

4.配置AK(全部粘贴)
cat > /opt/soft/tool/certbot/credentials.ini < 
chmod 600 /opt/soft/tool/certbot/credentials.ini   #赋予文本权限
5.申请证书 my.com是你在nginx解析的域名(全部粘贴)
/opt/soft/tool/certbot/venv/bin/certbot certonly 
-a certbot-dns-aliyun:dns-aliyun 
--certbot-dns-aliyun:dns-aliyun-credentials /opt/soft/tool/certbot/credentials.ini 
-d my.com 
-d "*.my.com"

成功申请后,会有提示证书的存放位置。

6.在nginx配置证书(文本贴入nginx.conf)
server {
		listen 443 ssl;
		server_name my.com;
		client_max_body_size 80M;
		ssl_certificate  /etc/letsencrypt/live/my.com/fullchain.pem; 
		ssl_certificate_key /etc/letsencrypt/live/my.com/privkey.pem;
		ssl_session_timeout 5m;
		ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
		ssl_ciphers ALL:!kEDH!ADH:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
		ssl_prefer_server_ciphers on;

		location / {
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_set_header Host $http_host;
			proxy_set_header X-Forwarded-Proto https;
			proxy_set_header X-Real-IP $remote_addr;
			proxy_redirect off;
			proxy_connect_timeout      20;
			proxy_send_timeout         60;
			proxy_read_timeout         60;
		}

		location = /favicon.ico {
			log_not_found off;
			access_log off;
		}
    }
7.因为Certbox颁发证书有效期90天,所有需要Centos自动续签
echo "0 0,12 * * * root python -c 'import random; import time; time.sleep(random.random() * 3600)' && /opt/soft/tool/certbot/venv/bin/certbot renew -q" | sudo tee -a /etc/crontab > /dev/null
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/488342.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号