# SSL 证书申请
很多网站都开始使用 SSL 了,甚至连小程序的接口访问都必须是 HTTPS,谷歌浏览器 HTTP 会显示不安全,HTTPS 目前已经是广泛普及了。下面是免费申请证书的方法。
# 使用 acme.sh 申请
大部分操作平台都能够使用acme.sh (opens new window),经过测试的操作平台 (opens new window)。
# 安装
# 在线安装
curl https://get.acme.sh | sh
# 或者
wget -O - https://get.acme.sh | sh
1
2
3
4
5
2
3
4
5
# 克隆项目
git clone https://github.com/Neilpang/acme.sh.git
cd ./acme.sh
./acme.sh --install
1
2
3
2
3
# 颁发证书
# HTTP 验证
acme.sh --issue -d <域名> -w <网站目录>
1
TIP
使用 HTTP 验证颁发的证书会在 60 天后自动更新。 只能单域名或多域名验证,通配证书需要使用 DNS 验证。
# dns 验证
TIP
- 阿里云
<解析商_id>
为Ali_Key
,<解析商_Key>
为Ali_Secret
,<解析商dns>
为dns_ali
。 - 腾讯云可以使用 DNSPod
<解析商_id>
为DP_Id
,<解析商_Key>
为DP_Key
,<解析商dns>
为dns_dp
。
export <解析商_id> = <用户id>
export <解析商_Key> = <用户Key>
acme.sh --issue --dns <解析商dns> -d <域名> -d <*.域名>
1
2
3
2
3
例如:
export Ali_Key="123"
export Ali_Secret="123123"
acme.sh --issue --dns dns_ali -d hxin.link -d *.hxin.link
1
2
3
2
3
WARNING
DNS 验证,无法自动更新证书。需要自己写脚本命令,设置一个定时任务。
# 安装证书
acme.sh --install-cert -d <域名> \
--cert-file <证书位置>\
--key-file <证书位置>\
--fullchain-file <证书位置>\
--reloadcmd <服务器重启命令>
1
2
3
4
5
2
3
4
5
以 Apache 为例:
acme.sh --install-cert -d hxin.link --cert-file ./ssl/cert.pem --key-file ./ssl/key.pem --fullchain-file ./ssl/fullchain.pem --reloadcmd "httpd.exe -k restart"
1
WARNING
最后需要使用证书,即服务器的配置的修改。这个是需要自己修改的。
← package