随记 使用certbot申请ssl证书
先是下载certbot
//CentOS + Nginx 用户:
sudo yum install epel-release // 这个是下面这个安装不了 才安装这个 要是下面这个能安装就直接安装
sudo yum install certbot python3-certbot-nginx -y
// 使用 certbot 获取证书
sudo certbot --nginx
这里查看版本没有问题后
// 这里可以直接用这个命令执行
sudo certbot --nginx// 然后就是他会自动做下面的事
检测 Nginx 配置
申请 HTTPS 证书(使用 Let’s Encrypt)
自动写入 SSL 配置到 Nginx 的站点配置中
自动重启 Nginx
注册自动续期计划任务
要是这个不行的话,比如我的,用的宝塔,默认的配置文件不在
/etc/nginx/nginx.conf 这个位置,他会找不到
那么我就用 webroot模式 等下面配置好了,再运行
certbot certonly --webroot -w /www/wwwroot/域名的名字的文件夹 -d 域名
现在需要什么呢,那个发证书的要给你这个发消息确认,不然肯定不会给你发的,所以我们要写一个回应的,
mkdir -p /www/wwwroot/域名名字的文件夹/.well-known/acme-challengeecho "hello" > /www/wwwroot/域名名字的文件夹/.well-known/acme-challenge/test
再配置一个nginx的配置
server {listen 80;server_name 自己的域名;location ^~ /.well-known/acme-challenge/ {allow all;root /www/wwwroot/文件名;}root /www/wwwroot/文件文件名;index index.html;location / {try_files $uri $uri/ /index.html;}
}
nginx -t
nginx -s reload
运行命令
certbot certonly --webroot -w /www/wwwroot/域名的名字的文件夹 -d 域名