使用Cerbot快速免费申请https

04/15/2024

背景

算了,就不再讲https跟http的区别了,这里直接上怎么申请吧

具体步骤

  • 在服务器安装nginx

  • 把自己的域名,解析到这个ip

  • 写入自己的nginx配置,我的如下

upstream youngliu-next {
  server 127.0.0.1:3000;
  keepalive 20;
}
server {
  server_name    www.youngliu.fun;
  location / {
    proxy_pass http://youngliu-next;
    proxy_read_timeout 60;
    proxy_connect_timeout 60;
    proxy_redirect off;
  }
}
server {
  server_name    www.youngliu.fun;
  listen 80;
}
  • install snapd
sudo apt update
sudo apt install snapd
  • Ensure snapd up to date
sudo snap install core
sudo snap refresh core
  • Remove certbot-auto
sudo apt-get remove certbot
  • Install certbot
sudo snap install --classic certbot
  • Prepare cerbot command
sudo ln -s /snap/bin/certbot /usr/bin/certbot
  • Run certbot nginx
sudo certbot --nginx
  • Test renewal
sudo certbot renew --dry-run

更多

之前在服务器上已经运行过cerbot的话,在修改了nginx配置之后,可以直接走到Run certbot nginx部分。

参考: https://certbot.eff.org/instructions?ws=nginx&os=ubuntufocal