差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录前一修订版
后一修订版
前一修订版
it:server:security [2023-04-08 11:46] – [SSL 证书] goldentianyait:server:security [2025-12-30 14:55] (当前版本) – [ACME 证书] goldentianya
行 57: 行 57:
 </code> </code>
  
-====== SSL 证书 ====== 
-利用Cerbot(([[https://certbot.eff.org/lets-encrypt/ubuntufocal-nginx|SSL Certificates with Certbot]]))获取证书。按照官网的指令([[https://certbot.eff.org|官方文档]]) ([[https://www.cnblogs.com/redirect/p/10140248.html|中文文档]]), 
-<konsole> 
-$ sudo apt install snap 
-$ sudo snap install core; sudo snap refresh core 
-$ sudo snap install --classic certbot 
-$ sudo ln -s /snap/bin/certbot /usr/bin/certbot 
-$ sudo certbot --nginx # 应用此证书到Nginx服务器 
-</konsole> 
  
-最后为两个域名生成证书,将这两份证书重新复制到别的主机,应该也可以用。 
-<konsole> 
-Successfully received certificate. 
-Certificate is saved at: /etc/letsencrypt/live/wiki.goldentianya.de/fullchain.pem 
-Key is saved at:         /etc/letsencrypt/live/wiki.goldentianya.de/privkey.pem 
-This certificate expires on 2021-10-21. 
-These files will be updated when the certificate renews. 
-Certbot has set up a scheduled task to automatically renew this certificate in the background. 
-</konsole> 
  
-显示当前证书:<color #ff7f27>''%%certbot certificates%%''</color>\\ 
-证书的有效期为三个,需要用下面命令定期更新:<color #ff7f27>''%%sudo certbot renew --dry-run 
-%%''</color> \\ 
-或者添加定时任务 <color #ff7f27>''%%0 0 1 * * /usr/bin/certbot renew --quiet%%''</color> (每月1号更新一下)\\ 
-接着到Nginx的conf配置文件中更改证书目录就可以了。 
-如果需要迁移的第二台服务器,直接压缩certbot的文件夹就好了。 <color #ff7f27>''%%tar zpcvf backup.tar.gz /etc/letsencrypt/%%''</color> 
  
  
-为主域名和下面的子域名申请通配证书 
-(([[https://www.infoq.cn/article/2018/03/lets-encrypt-wildcard-https|Let's Encrypt 宣布支持通配符证书]]))  
-<code bash> 
-certbot certonly  -d *.simperator.com --manual --preferred-challenges dns 
-# -d 为那些主机申请证书,如果是通配符,输入 *simperator.com 
-# –preferred-challenges dns,使用 DNS 方式校验域名所有权 
-</code> 
-<color #c3c3c3>* 可以使用certonly或run命令来创建一个新证书,即使已经存在具有该域名的证书,也没有关系,那么certbot会更新该证书,否则会创建一个新证书,一句话存在就更新,不存在就创建</color> 
  
-按照指示添加TXT记录,成功后存储在 <color #7092be>/etc/letsencrypt/archive/simperator.com</color> 
- 
-校验证书: 
-<code bash> 
-openssl x509 -in  /etc/letsencrypt/archive/simperator.com/cert1.pem -noout -text 
-</code> 
- 
-<code> 
-// 显示证书的起始日期(Not Before)和到期日期(Not After) 
-openssl x509 -in <证书文件路径> -noout -dates 
-// <域名或IP> 是您要查看的SSL证书所属的域名或IP地址,<端口> 是SSL连接使用的端口。以上命令将显示证书的有效期信息 
-gnutls-cli -V --print-cert <域名或IP>:<端口> 
-</code> 
- 
-为域名更换证书 [[https://askubuntu.com/questions/1009896/how-to-change-letsencrypt-certbot-domain|change Domain]] 
- 
-更新邮件地址  
-<code | download> 
-certbot register --update-registration --email <email> 
-certbot update_account --email [email protected] 
-</code> 
- 
-打开 <color #7092be>/etc/letsencrypt/renewal</color> 文件夹下查看 *.conf 文件就能知道目前用的是哪个 ++ account | ab1af729afa2219047bb043c53f97fc9 ++ 。(当前我申请的两个证书都是同一个aacount) 
- 
-为每一个子域名配置证书,如 xx.simperator.com,有多少个子网站就重复多少次。Certbot会找到Nginx并正确的配置。 
-<code bash> 
-certbot --nginx -d fun.simperator.com 
-</code> 
- 
- 
-端口分配的设置参考[[https://www.cyberciti.biz/faq/linux-unix-nginx-redirect-all-http-to-https/|Nginx Redirect HTTP To HTTPS]] / [[https://www.digitalocean.com/community/tutorials/how-to-configure-nginx-with-ssl-as-a-reverse-proxy-for-jenkins|How To Configure Nginx with SSL as a Reverse Proxy for Jenkins]] 
- 
-**吊销证书**\\ 
-严格来说不需要吊销一个证书,除非自己已经对这个域名失去控制。只要删除证书就好,三个月后会自动过期。并且<color #ff7f27>''%%revoke%%''</color>命令也不会删除,下次renew的时候还是会被更新。 
-<code> 
-certbot delete --cert-name MyDomain 
-</code> 
- 
-== sslforfree == 
- 
-另外一种申请证书的方式 [[https://www.sslforfree.com/|免费ssl证书]] 
-====== SSL 更新 ====== 
-更新证书遇到错误: 
-<code> 
-sudo certbot renew --dry-run 
- 
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
-Processing /etc/letsencrypt/renewal/simperator.com.conf 
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
-Failed to renew certificate simperator.com with error: The manual plugin is not working; there may be problems with your existing configuration. 
-The error was: PluginError('An authentication script must be provided with --manual-auth-hook when using the manual plugin non-interactively.') 
- 
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
-All renewals failed. The following certificates could not be renewed: 
-  /etc/letsencrypt/live/simperator.com/fullchain.pem (failure) 
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
-1 renew failure(s), 0 parse failure(s) 
-Ask for help or search for solutions at https://community.letsencrypt.org. See the logfile /var/log/letsencrypt/letsencrypt.log or re-run Certbot with -v for more details. 
-</code> 
- 
-尝试新的命令 
-<code | download> 
-certbot certonly --manual -d *.simperator.com 
-</code> 
- 
-更新证书后要重启服务器 <color #ff7f27>''%%sudo systemctl restart nginx%%''</color> 
- 
-将 <color #ff7f27>''%%/etc/letsencrypt/archive/simperator.com/*.pem%%''</color> 文件拷贝到第二台计算机上,<color #ff7f27>''%%ln -s%%''</color> 命令更新软链接,就可以在新的计算机上使用此证书。  
- 
-為了防止過多的 TXT 紀錄,以後要刪除舊的紀錄。ionos 1小時, pi server 2小時。 
- 
-buypass TLS 证书可以6个月有效 
-    certbot certonly --standalone --agree-tos -d www.simperator.com -d simperator.com --server https://api.buypass.com/acme/directory 
- 
- 
-====== ACME 证书 ====== 
- 
-[[https://wsgzao.github.io/post/acme/|ACME 证书申请讲解]] 
- 
-<code bash> 
-apt install -y socat 
-curl  https://get.acme.sh | sh 
-~/.acme.sh/  // 安装到自己目录下 
-</code> 
- 
-注册证书 
-<code bash> 
-~/.acme.sh/acme.sh --register-account -m [email protected] 
-// 开通 80 和 443 端口,否则无法监听  
-// 如果一直不通就加上参数 --server letsencrypt 
-~/.acme.sh/acme.sh  --issue -d simperator.top   --standalone 
-</code> 
- 
-安装完成后会自动更新证书,查看crontab 会发现这条命令\\ 
-<wrap lo>root@serverpi:~# crontab -l \\ 
-40 0 * * * "/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" > /dev/null</wrap> 
- 
-拷贝证书到指定地点  
-<code bash> 
-~/.acme.sh/acme.sh --installcert -d simperator.top --key-file /root/ssl-keys/private.key --fullchain-file /root/ssl-keys/cert.crt 
- 
-</code>  
-   
-<wrap em>没有通配证书,simperator.top 和 ionos.simperator.top 要分别申请。</wrap> 
- 
-**为 nginx 配置证书** 
-以域名 ionos.simperator.top 为例 
- 
-1. 申请证书 <color #ff7f27>''%%acme.sh --issue  -d ionos.simperator.top   --nginx%%''</color> 
- 
-2. 创建文件夹 <color #ff7f27>''%%mkdir -p /etc/nginx/ssl/ionos.simperator.top%%''</color> 
- 
-3. 拷贝证书 
-<code bash> 
-~/.acme.sh/acme.sh --install-cert -d ionos.simperator.top \ 
---key-file        /etc/nginx/ssl/ionos.simperator.top/key.pem  \ 
---fullchain-file  /etc/nginx/ssl/ionos.simperator.top/cert.pem \ 
---reloadcmd     "service nginx force-reload" 
-</code> 
- 
-4 配置 conf 文件 
-<code> 
-ssl_certificate "/etc/nginx/ssl/ionos.simperator.top/cert.pem"; 
-ssl_certificate_key "/etc/nginx/ssl/ionos.simperator.top/key.pem"; 
-ssl_session_cache shared:SSL:1m; 
-ssl_session_timeout  10m; 
-ssl_ciphers HIGH:!aNULL:!MD5; 
-ssl_prefer_server_ciphers on; 
- 
-# Load configuration files for the default server block. 
-include /etc/nginx/default.d/*.conf; 
-</code> 
- 
-查看证书 <wrap em>acme.sh list</wrap> 有效日期 
- 
-<WRAP center round important 60%> 
-cloudflare 现在已经不支持通过API设置.cf, .ga, .gq, .ml, 或.tk域名的DNS记录,在acme.sh设置TXT记录时会出错。只能单个证书申请。 
-</WRAP> 
- 
- 
-===== cloudflare ===== 
- 
-托管在 cloudflare 上的域名参考 [[https://blog.augustdoit.men/acme/|用 acme.sh 脚本申请 SSL 证书并自动更新]] 以及 [[https://www.zatp.com/post/auto-update-ssl-with-acme/|使用 acme.sh 自动签发和更新证书]] 
- 
-定时任务更新证书,并重新加载 nginx  
- 
-<code> 
-0 3 15 */2 * acme.sh --installcert -d simperator.com --fullchain-file /root/ssl-keys/fullchain.pem --key-file /root/ssl-keys/private.key --ecc && /etc/init.d/nginx reload 
-</code> 
- 
-自动更新 <color #ff7f27>''%%acme.sh --upgrade --auto-upgrade%%''</color> 
- 
-其实可以使用 cloudflare 的源服务器证书。需要开启 
-  - 完全加密 
-  - 始终使用 HTTPS  
-  - 打开小黄朵 
-  - 配置通配的边缘证书 
- 
-<WRAP center round tip 100%> 
-您的域/子域在 Cloudflare 的网络上未处于活动状态 
-Cloudflare 的 SSL 仅在您验证了根或 www DNS 记录的 SSL 证书后,才会向您网站的访问者显示,方法是在仪表板中将这些记录涂成橙色。如果 DNS 记录是灰色的,则 Cloudflare 颁发的 SSL 证书将不存在。 
-</WRAP> 
  
  
      
-{{tag>vps ubuntu}}+{{tag>vps ubuntu acme}}
it/server/security.1680954402.txt.gz · 最后更改: 2023-04-08 11:46 由 goldentianya
回到顶部
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0