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 />
[root@localhost ~]# cd ~/.acme.sh/[root@localhost .acme.sh]# lsaccount.conf acme.sh acme.sh.csh acme.sh.env deploy dnsapi notify# (1) 执行acme.sh 安装[root@localhost .acme.sh]# acme.shbash: acme.sh: command not found...### 不能执行,检查bashrc文件[root@localhost .acme.sh]# vim ~/.bashrc---------------------------------------------------# .bashrc# User specific aliases and functionsalias rm='rm -i'alias cp='cp -i'alias mv='mv -i'# Source global definitionsif [ -f /etc/bashrc ]; then. /etc/bashrcfi. "/root/.acme.sh/acme.sh.env" <-- 已添加---------------------------------------------------### 重新载入bashrc文件[root@localhost .acme.sh]# source ~/.bashrc#(2) 检查定时任务:[root@localhost .acme.sh]# crontab -e47 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;}}
