Ubuntu使用Certbot生成https证书

更新包列表

sudo apt update

安装nginx

apt install nginx

安装 Certbot

nginx:

sudo apt install certbot python3-certbot-nginx

Apache:

sudo apt install certbot python3-certbot-apache

配置nginx

server {
    listen 80;
    server_name example.com www.example.com;

    # 根目录
    root /var/www/web/Viabilidad;
    index index.html index.htm index.nginx-debian.html;

    # 日志文件
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    # 静态文件
    location / {
        try_files $uri $uri/ =404;
    }

    # 可选:重定向 www 到非 www
    if ($host = example.com) {
        return 301 http://www.example.com$request_uri;
    }
}

获取并安装证书

nginx:

sudo certbot --nginx

apache:

sudo certbot --apache

自动续订证书

Certbot 会自动设置一个定时任务来续订证书。你可以手动测试续订过程:

sudo certbot renew --dry-run

也可以通过命令查看定时任务:

sudo cat /etc/cron.d/certbot

验证安装

certbot --version
除非注明,否则均为Life · Dot原创文章,转载必须以链接形式标明本文链接

本文链接:https://www.lifd.site/tech/ubuntu-shi-yong-certbot-sheng-cheng-https-zheng-shu/

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

You can use the Markdown in the comment form.

相关文章

开始在上面输入您的搜索词,然后按回车进行搜索。按ESC取消。

返回顶部