我们有时候会有 SSL 需求,但是国内的证书都需要买,价格也有问题,因此这里写一篇博客,教会大家如何使用 certbot
和 let's encrypt
。
Let's Encrypt
是一个免费的 SSL 服务。
certbot
用来自动化 ssl 签名,来提供 https。
Debian/Ubuntu 安装依赖
sudo apt update
sudo apt install certbot python3-certbot-nginx
添加配置文件
sudo nano /etc/nginx/sites-available/subdomain.example.com.conf
文件中添加 nginx 的配置信息
server {
listen 80;
server_name subdomain.example.com;
root /var/www/subdomain.example.com;
index index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
}
启用和部署 HTTPS
启用配置文件: sudo ln -s /etc/nginx/sites-available/subdomain.example.com.conf /etc/nginx/sites-enabled/
.
添加域名即可
sudo certbot --nginx -d subdomain.example.com.