https://github.com/acmesh-official/acme.sh
注意
- nginx版本不要太低
- acme.sh v3.0以后,默认 CA变成了ZeroSSL
(https://github.com/acmesh-official/acme.sh/wiki/Change-default-CA-to-ZeroSSL)
- nginx command is not found. 错误:Nginx模式。需要给Nginx做一个软连接
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/nginx
- Can not find nginx conf 错误:加上指定的域名配置文件
acme.sh —issue -d 域名 —nginx /usr/local/nginx/conf/conf.d/域名配置
- 关掉防火墙
1. 安装acme.sh
curl [https://get.acme.sh](https://get.acme.sh) | sh<br />![](https://cdn.nlark.com/yuque/0/2022/png/288528/1648171759105-d476ae51-504f-4d33-bdde-76ae5e873abc.png#crop=0&crop=0&crop=1&crop=1&id=jhyfZ&originHeight=530&originWidth=1083&originalType=binary&ratio=1&rotation=0&showTitle=false&status=done&style=none&title=)
[root@localhost ~]# cd ~/.acme.sh/
[root@localhost .acme.sh]# ls
account.conf acme.sh acme.sh.csh acme.sh.env deploy dnsapi notify
# (1) 执行acme.sh 安装
[root@localhost .acme.sh]# acme.sh
bash: acme.sh: command not found...
### 不能执行,检查bashrc文件
[root@localhost .acme.sh]# vim ~/.bashrc
---------------------------------------------------
# .bashrc
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
. "/root/.acme.sh/acme.sh.env" <-- 已添加
---------------------------------------------------
### 重新载入bashrc文件
[root@localhost .acme.sh]# source ~/.bashrc
#(2) 检查定时任务:
[root@localhost .acme.sh]# crontab -e
47 0 * * * "/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" > /dev/null
nginx配置
server {
server_name domain.com;
listen 80;
location / {
root /www/html/;
index index.html;
}
#这里很重要,当Letsencrypt验证你的域名有效性时
#会访问domain.com/.well-know/acme-challenge/这个目录下是否有acme认证文件
#此处我们需要对这个root单独进行管理,而不应该放置在任何站点www文件下
location /.well-know/acme-challenge/ {
root /www/ssl/;
log_not_found off;
}
}
2. 获取证书
acme.sh --issue -d domain.com -w /www/ssl/
—issue 去创造
-d d,指的是domain,后跟域名
-w 指定domain.com/.well-know/acme-challenge/设置的文件夹
3. 安装证书到nginx
acme.sh --install-cert -d domain.com \
--key-file /www/ssl/domain.com.key \ #指定将keyfile存放哪里
--fullchain-file /www/ssl/domain.com.pem \
--reloadcmd "service nginx force-reload"
4. 修改nginx配置
server {
# 当http协议被请求时,统一转发到https协议商
listen 80;
listen [::]:80; #IPV6协议
server_name domain.com;
rewrite ^(.*)$ https://$host$1 permanent;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
ssl_certificate /www/ssl/domain.com.pem; #证书文件
ssl_certificate_key /www/ssl/domain.com.key;
server_name domain.com;
location / {
root /www/html/;
index index.html;
}
location /.well-know/acme-challenge/ {
root /www/ssl/;
log_not_found off;
}
}