通配符证书
即一个证书能给ldsun.com
、www.ldsun.com
、 btc.www.ldsun.com
等所有的*.ldsun.com
域名使用的证书,四不四很爽。
免费证书
使用 let's encrypted
免费开源https证书,目前已经支持通配符证书申请。
使用脚本
使用国人开发的脚本acme.sh
简化配置流程。
DNS解析商
鉴于国内DNS服务商的尿性,选择digitalocean
作为DNS解析商,抛弃dnspod
,dnspod
在设置证书过程中出现各种问题。
digitalocean
需要PayPal支付验证。验证后添加域名,添加解析记录。
配置步骤
1、安装acme脚本
1 2
| curl https://get.acme.sh | sh source ~/.bashrc
|
2、申请设置 Digitalocean API
1
| export DO_API_KEY="753112c4ca779ac39a19f635213b573b49ce92ae126553ebd61ac3a300934834cc"
|
3、申请通配符证书
1
| acme.sh --issue -d ldsun.com -d '*.ldsun.com' --dns
|
4、安装证书
1 2 3 4
| acme.sh --install-cert -d ldsun.com \ --key-file /etc/nginx/ssl/ldsun.com.key \ --fullchain-file /etc/nginx/ssl/ldsun.com.crt \ --reloadcmd "service nginx force-reload"
|
5、配置Nginx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| server { listen 443 ssl http2 default_server; listen [::]:443 ssl http2 default_server;
server_name ldsun.com www.ldsun.com;
location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; proxy_pass http://127.0.0.1:2368; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }
location ^~ /wp-content/ { if (!-e $request_filename) { rewrite ^/wp-content/uploads/(.*)$ https://obmv8nk23.qnssl.com/$1 last; break; } }
# 我们采用强大的迪菲-赫尔曼密钥交换,生成命令 openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048 ssl_dhparam /etc/nginx/ssl/dhparam.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS'; ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:50m; ssl_session_timeout 1d;
# 此处是证书文件 ssl_certificate /etc/nginx/ssl/ldsun.com.crt; ssl_certificate_key /etc/nginx/ssl/ldsun.com.key;
# 开启 HSTS Preload 支持 add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload"; add_header X-Frame-Options SAMEORIGIN; add_header X-Content-Type-Options nosniff; add_header X-XSS-Protection "1; mode=block";
access_log /var/log/nginx/ldsun.com.access.log; error_log /var/log/nginx/ldsun.com.error.log; }
server { if ($host = www.ldsun.com) { return 301 https://$host$request_uri; } # managed by Certbot if ($host = ldsun.com) { return 301 https://$host$request_uri; }
listen 80; server_name ldsun.com www.ldsun.com; return 404; } ...
|
6、续期
1 2
| acme.sh --renew -d ldsun.com -d '*.ldsun.com' --force # 默认是自动更新,添加 --force 强制手动更新
|
参考:
https://sb.sb/blog/linux-acme-sh-lets-encrypt-ssl/
https://sb.sb/blog/linux-lets-encrypt-wildcard-ssl/