惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

SecWiki News
SecWiki News
量子位
The Cloudflare Blog
美团技术团队
T
The Exploit Database - CXSecurity.com
博客园 - 【当耐特】
Spread Privacy
Spread Privacy
P
Proofpoint News Feed
C
CXSECURITY Database RSS Feed - CXSecurity.com
博客园 - 三生石上(FineUI控件)
T
Tor Project blog
博客园 - 司徒正美
宝玉的分享
宝玉的分享
T
Threatpost
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
S
Secure Thoughts
T
Threat Research - Cisco Blogs
Hacker News: Ask HN
Hacker News: Ask HN
Jina AI
Jina AI
博客园 - 聂微东
A
Arctic Wolf
I
Intezer
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Know Your Adversary
Know Your Adversary
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
爱范儿
爱范儿
Hugging Face - Blog
Hugging Face - Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
小众软件
小众软件
T
Tailwind CSS Blog
The Hacker News
The Hacker News
L
LINUX DO - 最新话题
Hacker News - Newest:
Hacker News - Newest: "LLM"
WordPress大学
WordPress大学
S
SegmentFault 最新的问题
TaoSecurity Blog
TaoSecurity Blog
Project Zero
Project Zero
博客园 - 叶小钗
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Cloudbric
Cloudbric
雷峰网
雷峰网
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
大猫的无限游戏
大猫的无限游戏
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Troy Hunt's Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
V2EX - 技术
V2EX - 技术
The GitHub Blog
The GitHub Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy & Cybersecurity Law Blog

Sehnsucht

记一次博客换图床的过程 观《花束般的恋爱》 读《活过》 东京 旅行篇 亲人逝去 我为什么想养鱼 防止AI爬取你的博客 「monthly 」博客重构 游戏全成就 好看的小说 人生的每一步都不会是浪费-2024年终 「weekly」星期五综合征 「weekly」听播客 杂谈 读《美丽新世界》 「weekly」社交媒体 恶性事件 新世界 「weekly」认知觉醒 美丽新世界 follow 「weekly」独立博客9问题 双十一买书 读《惊呆了!原来这就是社会学》 一次聊天与自我建设 2024-09月记 补番《relife》 树状数组简单理解 lvm简单使用 博客自动发布方案 某公众号废案 fail2ban基本使用 Podman 环境使用 Nginx Proxy Manager 最佳实践 2024-07同学聚会 vps使用podman部署freshrss Gitlab CICD 实践,思考与记录 装备升级:新的PC gitlab局域网搭建流程 FastMail迁移至GMail+Cloudflare Email Routing 读《黑客与画家》 leetcode 第 391 场周赛 Astro添加过渡后DarkModeToggle按钮失效 nuxt3使用echarts5渲染中国地图 人生刻度 又到凤凰花朵开放的时候 2023-05-10 实习结束 2023-04-26 广州博物馆游记 YOASOBI「たぶん」官方音乐视频 风灵玉秀-发如雪 带我的老哥离职了 从p10k转向Starship lunarvim国内安装踩坑记录 什么是对称加密非对称加密、密钥交换、数字签名、证书 强调体验的一种思考时间的方式 ArchLinux使用vscode编写latex报错The font "FontAwesome" cannot be found ArchLinux安装(移动硬盘)流程 yay一个或多个文件没有通过有效性检查! 2022年终 hugo建站伊始 clash设置relay前置代理(校园网破解改进记录) 群青 · YOASOBI · Ayase 华为 matepad pro 11使用体验 永远属于你的安娜 在线 童年趣事 童心,是比野心更难得的梦想 2021年终总结 基于jeeSite的软件测试课程作业 流程记录 Linux不同用户安装不同版本jdk Wifi4更换Wifi6路由器的使用体验 Flask 上传图片并灰度显示 玩客云刷机debain个人记录 jython 简单入门 Jenkins 个人搭建流程记录 集成邮件系统(qq邮箱),gitlab服务器,freestyle风格 在Web项目中配置Log4j --指南-- Codeforces Round 753 (Div. 3) ABCDE 浅谈fork函数 JavaWeb servlet 使用Cookie记录用户访问次数 Codeforces Round Educational Codeforces Round 114 (Rated for Div. 2) ABC 2021牛客多校7 I xay loves or 2021牛客多校9 H Happy Number 2021牛客多校8 D OR 2021牛客多校5 B Boxes 2021牛客多校5 H Holding Two 2021牛客多校2 D Er Ba Game 2021牛客多校1 F Find 3-friendly Integers 2021牛客多校1 B Ball Dropping 记人生第一次投简历和笔试 原型模式 2021-2-20 雨时随记 关于一维差分数组的例子 halo个人建站 关于手机ping电脑和电脑ping手机 泛型类简单理解 CodeForces - 849C From Y to Y 2020牛客国庆集训派对day3 Leftbest 约瑟夫环问题---2020牛客国庆集训派对day2 AKU NEGARAKU mysql 5.7 忘记密码如何更改 CF 1099B Squares and Segments CF 998A Balloons CF 998B Cutting 链表应用之多项式相加 CF 1150A Stock Arbitraging CF 1199A City Day CF 1199B Water Lily CF 982A Row CF 934A A Compatible Pair CF 629B Far Relative’s Problem 651A Joysticks 651B Beautiful Paintings
Nginx使用acme.sh免费安装ssl证书
2022-07-25 · via Sehnsucht

后面改用cerbot了,因为到期后再续签有问题搞不定

[root@Cai certbot]# certbot --nginx
Saving debug log to /var/log/letsencrypt/letsencrypt.log

Which names would you like to activate HTTPS for?
We recommend selecting either all domains, or all domains in a VirtualHost/server block.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: sehnsucht.top
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1
Renewing an existing certificate for sehnsucht.top

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/sehnsucht.top/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/sehnsucht.top/privkey.pem
This certificate expires on 2023-01-30.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

Deploying certificate
Successfully deployed certificate for sehnsucht.top to /etc/nginx/nginx.conf
Your existing certificate has been successfully renewed, and the new certificate has been installed.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like Certbot, please consider supporting our work by:
 * Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
 * Donating to EFF:                    https://eff.org/donate-le
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[root@Cai certbot]# certbot renew --dry-run
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/sehnsucht.top.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Account registered.
Simulating renewal of an existing certificate for sehnsucht.top

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations, all simulated renewals succeeded: 
  /etc/letsencrypt/live/sehnsucht.top/fullchain.pem (success)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

以下为正文


acme.sh 实现了 acme 协议, 可以从 letsencrypt 生成免费的证书.

自动化证书管理环境(ACME)是用于自动验证X.509证书的域验证,安装和管理的标准协议,它是由Let's Encrypt开发的,Let's Encrypt是一个免费的证书颁发机构

名词说明

CA(Certificate Authority) 数字证书认证机构,也称为电子商务认证中心、电子商务认证授权机构;是负责发放和管理数字证书的权威机构,并作为电子商务交易中受信任的第三方,承担公钥体系中公钥的合法性检验的责任。

.key 文件 私钥

.csr 文件(certificate signing request) 证书签名请求文件;含有公钥信息及相关资讯的档案。

.crt 文件(certificate) 用.csr 生成的证书文件(包含了由私钥文件生成的公钥)。

x.509 是密码学里公钥证书的格式标准。X.509证书里含有公钥、身份信息(比如网络主机名,组织的名称或个体名称等)和签名信息(可以是证书签发机构CA的签名,也可以是自签名)

RA(Registration Authority) 数字证书注册审批机构,给申请数字证书者发放证书,发放前对申请者进行审合登记,它是CA的延伸机构。

PKI(Public Key Infrastructure) 公钥基础设施,由密钥管理(发放,吊销),密钥合法性验证,认证机构,密钥发放等组成。为数据完整性,隐私性,数据身份认证等提供基础服务。

步骤

主要步骤:

  1. 安装 acme.sh
  2. 生成证书
  3. copy 证书到 nginx
  4. 更新证书

下面详细介绍.

安装很简单, 一个命令:

curl  https://get.acme.sh | sh -s email=你的邮箱@example.com

普通用户和 root 用户都可以安装使用. 安装过程进行了以下几步:

  1. 把 acme.sh 安装到你的 home 目录下:
~/.acme.sh/

并创建 一个 bash 的 alias, 方便你的使用: alias acme.sh=~/.acme.sh/acme.sh

  1. 自动为你创建 cronjob, 每天 0:00 点自动检测所有的证书, 如果快过期了, 需要更新, 则会自动更新证书.

更高级的安装选项请参考: https://github.com/Neilpang/acme.sh/wiki/How-to-install

安装过程不会污染已有的系统任何功能和文件, 所有的修改都限制在安装目录中: ~/.acme.sh/

2. 生成证书

[[acme.sh中文文档#2 生成证书]]

acme.sh 实现了 acme 协议支持的所有验证协议. 一般有两种方式验证: http 和 dns 验证.

http 方式需要在你的网站根目录下放置一个文件, 来验证你的域名所有权,完成验证. 然后就可以生成证书了.

只需要指定域名, 并指定域名所在的网站根目录. acme.sh 会全自动的生成验证文件, 并放到网站的根目录, 然后自动完成验证. 最后会聪明的删除验证文件. 整个过程没有任何副作用.

用的 nginx服务器, 或者反代, acme.sh 还可以智能的从 nginx的配置中自动完成验证, 你不需要指定网站根目录:

acme.sh --issue -d {你的域名} --nginx {你的nginx配置文件地址}

注意, 无论是 apache 还是 nginx 模式, acme.sh在完成验证之后, 会恢复到之前的状态, 都不会私自更改你本身的配置. 好处是你不用担心配置被搞坏, 也有一个缺点, 你需要自己配置 ssl 的配置, 否则只能成功生成证书, 你的网站还是无法访问https. 但是为了安全, 你还是自己手动改配置吧.

我个人输入的是

acme.sh --issue -d sehnsucht.top --nginx /www/server/nginx/conf/nginx.conf

宝塔的Nginx配置文件是/www/server/nginx/conf/nginx.conf

更高级的用法请参考: https://github.com/Neilpang/acme.sh/wiki/How-to-issue-a-cert

3. copy/安装 证书

[[acme.sh中文文档#3 copy 安装 证书]]

前面证书生成以后, 接下来需要把证书 copy 到真正需要用它的地方.

注意, 默认生成的证书都放在安装目录下: ~/.acme.sh/, 请不要直接使用此目录下的文件, 例如: 不要直接让 nginx/apache 的配置文件使用这下面的文件. 这里面的文件都是内部使用, 而且目录结构可能会变化.

正确的使用方法是使用 --install-cert 命令,并指定目标位置, 然后证书文件会被copy到相应的位置, 例如:

Nginx example:

acme.sh --install-cert -d example.com \
--key-file       /path/to/keyfile/in/nginx/key.pem  \
--fullchain-file /path/to/fullchain/nginx/cert.pem \
--reloadcmd     "service nginx force-reload"

一个小提醒, 这里用的是 service nginx force-reload, 不是 service nginx reload, 据测试, reload 并不会重新加载证书, 所以用的 force-reload

两个路径其实是自定义的存放文件的路径,所以我选择放在了/www/ssl下面

force-reload我换成了restart,这样确定可以重新加载证书

acme.sh --install-cert -d example.com \
--key-file       /www/ssl/key.pem  \
--fullchain-file /www/ssl/cert.pem \
--reloadcmd     "service nginx restart"
# 实际上我的配置是下面的
./acme.sh --install-cert -d sehnsucht.top \
--key-file /www/ssl/sehnsucht.top.key.pem \
--fullchain-file /www/ssl/sehnsucht.top.cert.pem \
--reloadcmd     "service nginx restart"

Nginx 的配置 ssl_certificate 使用 /etc/nginx/ssl/fullchain.cer ,而非 /etc/nginx/ssl/<domain>.cer ,否则 SSL Labs 的测试会报 Chain issues Incomplete 错误。

--install-cert命令可以携带很多参数, 来指定目标文件. 并且可以指定 reloadcmd, 当证书更新以后, reloadcmd会被自动调用,让服务器生效.

详细参数请参考: https://github.com/Neilpang/acme.sh#3-install-the-issued-cert-to-apachenginx-etc

值得注意的是, 这里指定的所有参数都会被自动记录下来, 并在将来证书自动更新以后, 被再次自动调用.

4. 查看已安装证书信息

acme.sh --info -d {你的域名}
# 会输出如下内容:
DOMAIN_CONF=/root/.acme.sh/example.com/example.com.conf
Le_Domain=example.com
Le_Alt=no
Le_Webroot=dns_ali
Le_PreHook=
Le_PostHook=
Le_RenewHook=
Le_API=https://acme-v02.api.letsencrypt.org/directory
Le_Keylength=
Le_OrderFinalize=https://acme-v02.api.letsencrypt.org/acme/finalize/23xxxx150/781xxxx4310
Le_LinkOrder=https://acme-v02.api.letsencrypt.org/acme/order/233xxx150/781xxxx4310
Le_LinkCert=https://acme-v02.api.letsencrypt.org/acme/cert/04cbd28xxxxxx349ecaea8d07
Le_CertCreateTime=1649358725
Le_CertCreateTimeStr=Thu Apr  7 19:12:05 UTC 2022
Le_NextRenewTimeStr=Mon Jun  6 19:12:05 UTC 2022
Le_NextRenewTime=1654456325
Le_RealCertPath=
Le_RealCACertPath=
Le_RealKeyPath=/etc/acme/example.com/privkey.pem
Le_ReloadCmd=service nginx force-reload
Le_RealFullChainPath=/etc/acme/example.com/chain.pem

5. Nginx配置

对于Nginx的server模块,给出模板文件

server {  
    # server 当 http 协议被请求时,统一转发到 https 协议上  
    listen 80;  
    listen [::]:80; # IPV6 协议  
    server_name 你的域名;
    rewrite ^(.*)$ https://$host$1 permanent;  
}  
  
server {  
    listen 443 ssl;  
    listen [::]:443 ssl;  
    ssl_certificate /{cert文件路径}; # 例如:/www/ssl/cert.pem
    ssl_certificate_key /{key文件路径}; # 例如:/www/ssl/key.pem
  
    server_name 你的域名;
  
    location / {
	    # proxy_pass http://127.0.0.1:8888;
        root /www/xxx;  
        index index.html;
    }  
  
    location /.well-known/acme-challenge/ {  
        root {证书文件路径};  
        log_not_found off;  
    }  
}
server {
    # server 当 http 协议被请求时,统一转发到 https 协议上
    listen 80;
    listen [::]:80; # IPV6 协议
    server_name sehnsucht.top;
    rewrite ^(.*)$ https://$host$1 permanent;
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    ssl_certificate /www/ssl/sehnsucht.top.cert.pem;
    ssl_certificate_key /www/ssl/sehnsucht.top.key.pem;

    server_name sehnsucht.top;

    location /
    {
        proxy_pass http://127.0.0.1:1828;
        # root /www/xxx;
        # index index.html;
    }

    location /.well-known/acme-challenge/ {
        root /www/ssl/;
        log_not_found off;
    }
}

配置完成后访问网站就可以使用https了

6. 更新证书

[[acme.sh中文文档#5 更新证书]]

目前证书在 60 天以后会自动更新, 你无需任何操作. 今后有可能会缩短这个时间, 不过都是自动的, 你不用关心.

7.遇到的问题

域名:timeout

[[Linux如何改host]] 更改host后即可生效

acme没有自动更新

我手动更新了,输入了acme.sh --issue -d sehnsucht.top --nginx /www/server/nginx/conf/nginx.conf

失效原因参考: https://github.com/acmesh-official/acme.sh/issues/3855 https://github.com/acmesh-official/acme.sh/issues/3850 https://github.com/acmesh-official/acme.sh/issues/3842 报错信息:

[root@Cai .acme.sh]# acme.sh --issue -d sehnsucht.top --nginx /www/server/nginx/conf/nginx.conf --server letsencrypt --dns dns_cf
[Mon Oct 31 23:54:30 CST 2022] Using CA: https://acme-v02.api.letsencrypt.org/directory
[Mon Oct 31 23:54:30 CST 2022] Registering account: https://acme-v02.api.letsencrypt.org/directory
[Mon Oct 31 23:54:33 CST 2022] Register account Error: {
  "type": "urn:ietf:params:acme:error:invalidEmail",
  "detail": "Error creating new account :: invalid contact domain. Contact emails @example.com are forbidden",
  "status": 400
}
[Mon Oct 31 23:54:33 CST 2022] Please check log file for more details: /root/.acme.sh/acme.sh.log
[root@Cai .acme.sh]# 

账户邮箱的问题

[root@Cai .acme.sh]# acme.sh  --register-account  -m [email protected] --server zerossl
[Tue Nov  1 09:17:01 CST 2022] Registering account: https://acme.zerossl.com/v2/DV90
[Tue Nov  1 09:17:08 CST 2022] Already registered
[Tue Nov  1 09:17:08 CST 2022] ACCOUNT_THUMBPRINT='zXioZVdUEiREUBKV-tmy1_tNno7OaIYiYA1gqeWJNlo'

参考

官方文档 官方文档中文版 深入浅出解读http和https及ACME协议工作原理(另附域名证书申请教程)