acme申請ssl證書
# 安裝 Acme 腳本
curl https://get.acme.sh | sh
# 如果下載失敗
#curl: (35) TCP connection reset by peer
# 去能下載的主機復制過來
cat >> ~/.bashrc <<EOF
. "/root/.acme.sh/acme.sh.env"
EOF
. ~/.bashrc
# 設置為自動更新
acme.sh --upgrade --auto-upgrade
# 安裝 Acme 腳本之后,請先執行下面的命令(下面的郵箱為你的郵箱)
~/.acme.sh/acme.sh --register-account -m xxx@qq.com
[root@yang ~]# ~/.acme.sh/acme.sh --register-account -m xxx@qq.com
# 80 端口空閑的驗證申請
# 如果你還沒有運行任何 web 服務, 80 端口是空閑的, 那么 Acme.sh 還能假裝自己是一個 WebServer, 臨時監聽在 80 端口, 完成驗證
#~/.acme.sh/acme.sh --issue -d *.xxx.com --standalone
# Nginx 的方式驗證申請
# 這種方式需要你的服務器上面已經部署了 Nginx 環境,並且保證你申請的域名已經在 Nginx 進行了 conf 部署。(被申請的域名可以正常被打開)
# 貌似不能使用通配符的形式
~/.acme.sh/acme.sh --issue -d *.xxx.com --nginx
[root@yang ~]# ~/.acme.sh/acme.sh --issue -d *.xxx.com --nginx
[2021年 10月 13日 星期三 16:04:59 CST] Using CA: https://acme.zerossl.com/v2/DV90
[2021年 10月 13日 星期三 16:04:59 CST] Creating domain key
[2021年 10月 13日 星期三 16:04:59 CST] The domain key is here: /root/.acme.sh/*.xxx.com/*.xxx.com.key
[2021年 10月 13日 星期三 16:04:59 CST] Single domain='*.xxx.com'
[2021年 10月 13日 星期三 16:04:59 CST] Getting domain auth token for each domain
[2021年 10月 13日 星期三 16:05:05 CST] Getting webroot for domain='*.xxx.com'
[2021年 10月 13日 星期三 16:05:05 CST] Error, can not get domain token entry *.xxx.com for http-01
[2021年 10月 13日 星期三 16:05:05 CST] The supported validation types are: dns-01 , but you specified: http-01
[2021年 10月 13日 星期三 16:05:05 CST] Please add '--debug' or '--log' to check more details.
[2021年 10月 13日 星期三 16:05:05 CST] See: https://github.com/acmesh-official/acme.sh/wiki/How-to-debug-acme.sh
[root@yang ~]# ll /root/.acme.sh/*.xxx.com/
總用量 20
drwxr-xr-x 2 root root 4096 10月 13 16:07 backup
-rw-r--r-- 1 root root 380 10月 13 16:07 *.xxx.com.conf
-rw-r--r-- 1 root root 956 10月 13 16:04 *.xxx.com.csr
-rw-r--r-- 1 root root 148 10月 13 16:04 *.xxx.com.csr.conf
-rw-r--r-- 1 root root 1679 10月 13 16:04 *.xxx.com.key
# 安裝證書到指定文件夾
# 注意, 默認生成的證書都放在安裝目錄下: ~/.acme.sh/, 請不要直接使用此目錄下的證書文件。
# 正確的使用方法是使用 --install-cert 命令,並指定目標位置, 然后證書文件會被copy到相應的位置,比如下面的代碼
~/.acme.sh/acme.sh --installcert -d mydomain.com --key-file /root/private.key --fullchain-file /root/cert.crt
~/.acme.sh/acme.sh --installcert -d *.xxx.com --key-file /root/private.key --fullchain-file /root/cert.crt
#上面的 /root/private.key 以及 /root/cert.crt 是把密鑰和證書安裝到 /root 目錄,並改名為 private.key 和 cert.crt
cat: /root/.acme.sh/*.xxx.com/fullchain.cer: 沒有那個文件或目錄
#=================
# 再來一次
# 上一次找不到nginx的conf配置文件
~/.acme.sh/acme.sh --issue -d cd.xxx.com --nginx
# 這次ok
[2021年 10月 13日 星期三 16:44:36 CST] Your cert is in: /root/.acme.sh/cd.xxx.com/cd.xxx.com.cer
[2021年 10月 13日 星期三 16:44:36 CST] Your cert key is in: /root/.acme.sh/cd.xxx.com/cd.xxx.com.key
[2021年 10月 13日 星期三 16:44:36 CST] The intermediate CA cert is in: /root/.acme.sh/cd.xxx.com/ca.cer
[2021年 10月 13日 星期三 16:44:36 CST] And the full chain certs is there: /root/.acme.sh/cd.xxx.com/fullchain.cer
~/.acme.sh/acme.sh --installcert -d cd.xxx.com --key-file /root/private.key --fullchain-file /root/cert.crt
[root@k8s-master ~]# ~/.acme.sh/acme.sh --installcert -d cd.xxx.com --key-file /root/private.key --fullchain-file /root/cert.crt
[2021年 10月 13日 星期三 16:45:20 CST] Installing key to: /root/private.key
[2021年 10月 13日 星期三 16:45:20 CST] Installing full chain to: /root/cert.crt
mkdir -p /usr/local/nginx/cert/
mv /root/private.key /usr/local/nginx/cert/cd.xxx.com.private.key
mv /root/cert.crt /usr/local/nginx/cert/cd.xxx.com.cert.crt
server {
listen 443 ssl;
server_name cd.xxx.com;
#return 301 http://cd.xxx.com;
#rewrite ^(.*)$ http://cd.xxx.com;
ssl_certificate /usr/local/nginx/cert/cd.xxx.com.cert.crt;
ssl_certificate_key /usr/local/nginx/cert/cd.xxx.com.private.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
include /etc/nginx/proxy2.conf;
proxy_pass http://zentao;
}
}