【2】wordpress申请https证书
默认wordpress是http进行访问,http其实不安全,但是使用https访问,如果没申请证书会提示警告,这个时候就需要申请有效的证书并配置。默认在腾讯云控制台是可以申请域名证书的,但是有控制台申请的域名证书每次只有3个月,每次都需要手动下载替换。在linux中可以直接使用certbot机器人进行申请和自动替换,好处有2个。
- 可以申请https的ssl证书
- 可以自动续期
申请域名的前提条件: - 域名:需要已备案并有效的域名,并且该域名指向服务器。
- 服务器:1台VPS 或云服务器,并且上面安装了 Nginx 或 Apache。
- 操作系统: Debian、Ubuntu、CentOS系统
本次以ubuntu系统为例,安装的时nginx。
安装与申请
1. 更新软件源
sudo apt update
2. 安装Certbot
在ubuntu中,安装cerbot
sudo apt install certbot python3-certbot-nginx
3. 申请ssl证书
替换yourdomain为你的域名,比如我申请rrdsceo.cn,那么就一次性申请:rrdsceo.cn,www.rrdsceo.cn, blog.rrdsceo.cn;
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com -d blog.yourdomain.com
Certbot 会请求 Let's Encrypt 验证域名的控制权,通常 Certbot 会自动处理这个过程。验证成功后,它会安装证书并更新你的 web 服务器配置,比如查看:
sudo vim /etc/nginx/sites-enabled/default
sudo vim /etc/nginx/sites-enabled/yourdomain.com
都能看到有对应的443的https,则说明已经自动添加了
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name yourdomain.com;
# SSL configuration
ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
root /var/www/html; # 确保这个目录存在并有可访问的文件
index index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ =404;
}
}
这个时候访问https://yourdomain.com,确保 HTTPS 正常工作:
https://yourdomain.com
4. 自动续期
Let's Encrypt 的证书有效期为 90 天,因此建议设置一个 Cron 任务自动续期。
`注意:默认情况下,Certbot 会在安装时为你设置自动续期。
查看当前的所有证书
sudo certbot certificates
你可以运行以下命令来测试自动续期。
sudo certbot renew --dry-run
也可以查看是否正在进行后台任务运行
systemctl list-timers | grep certbot
能看到一条,则表明后台自动运行
Sun 2024-11-10 04:34:35 CST 2h 33min left Sat 2024-11-09 13:12:10 CST 12h ago certbot.timer certbot.service
5. 手动续期
有时候很奇怪,nginx启动如果443端口没有证书,无法启动,但是certbot又需要网站启动,所以可以手动启动。
sudo systemctl stop nginx
sudo certbot certonly --standalone \
-d blog.askerlab.com \
--cert-name blog.askerlab.com
sudo systemctl start nginx
如果有证书残留,一般证书放在以下三个位置,对应删除即可
sudo rm /etc/letsencrypt/live/git.askerlab.com -rf
sudo rm /etc/letsencrypt/archive/git.askerlab.com -rf
sudo rm /etc/letsencrypt/renewal/git.askerlab.com.conf -f本文发布于2024年11月10日01:42,已经过了414天,若内容或图片失效,请留言反馈 -
obsidian修改字体间距
背景 我的方案是使用云盘进行obsidian的文件同步的,各端都使用云盘进行数据的同步。最近刚买了macmini,配置在obsidian同步的时候,macos不知道为什么".obsidian"隐藏文件...
2024/11/18
-
优必选小方头刷小智机器人
1. 背景 最近在调研看智能萌宠机器人,正好看到网上有人买了优必选的小方头机器来刷目前的小智,所以买来试试。小方头机器人在2019年9月20日发布,售价1099元,现在咸鱼100块钱就能买到;小智机器...
2025/03/27
-
【2】emlog&obsidan同步
因为我一开始是使用的hexo来做博客,但是编写文章一直都是使用obsidian来进行编写的,然后通过obsidian的git推送到云端,触发云端git仓库的钩子,将obsidian的文档同步到对应的文...
2025/10/31
-
【5】emlog增加微信、抖音
1. 添加个人信息 更新最新的github代码,因为数据库里没有微信等信息,需要更新数据库信息。 bash 登录 sudo mysql -u root -p 查看数据库 SHOW DATABASES;...
2025/11/01
求索空间
apostle9891
360视觉云
360智慧生活
gitea
导航
hoppscotch
暂无评论