今天在 github 看到一个 project 用 certbot 来管理证书,试用了下感觉还蛮简单的。主要有:
- 开始的时候提供一个简版 nginx, 安装完 certbot 会自动修改 nginx conf
- 自动生成
/etc/cron.d/certbot
, 在 root 下面自动运行。
ps: Ubuntu Minimal 版本不带 cron, 所以要额外 sudo apt install cron
安装全过程:
- Install
nginx
:
sudo apt update
sudo apt install -y nginx certbot python3-certbot-nginx
- Put the following config into
/etc/nginx/sites-available/code-server
with sudo:
server {
listen 80;
listen [::]:80;
server_name mydomain.com;
location / {
proxy_pass http://localhost:8080/;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection upgrade;
proxy_set_header Accept-Encoding gzip;
}
}
Remember to replace mydomain.com
with your domain name!
- Enable the config:
sudo ln -s ../sites-available/code-server /etc/nginx/sites-enabled/code-server
sudo certbot --non-interactive --redirect --agree-tos --nginx -d mydomain.com -m me@example.com
Make sure to substitute me@example.com
with your actual email.
Visit https://<your-domain-name>
to access code-server
. Congratulations!