JAVA和Nginx 教程大全

网站首页 > 精选教程 正文

域名ssl证书越来越贵的今天,开启免费ssl证书的配置

wys521 2024-10-26 14:50:39 精选教程 40 ℃ 0 评论

1.环境准备

  • 服务器:你需要一台可以访问公网的服务器,推荐使用 Linux 操作系统(如 Ubuntu 或 CentOS)。
  • 域名:确保你有一个已注册的域名,并且 DNS 记录已经指向你的服务器 IP。

2.安装 Certbot

Certbot 是 Let's Encrypt 的客户端,用于生成和管理 SSL 证书。

在 Ubuntu 上安装 Certbot:

sudo apt update
sudo apt install certbot python3-certbot-nginx  # 如果使用 Nginx
sudo apt install certbot python3-certbot-apache  # 如果使用 Apache

在 CentOS 上安装 Certbot:

sudo yum install epel-release
sudo yum install certbot python2-certbot-nginx  # 如果使用 Nginx
sudo yum install certbot python2-certbot-apache  # 如果使用 Apache

3.创建一个 Web 服务

可以使用 Nginx 或 Apache 作为 Web 服务器来处理 HTTPS 请求,并在上面生成证书。

Nginx 示例配置:

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

    location /.well-known/acme-challenge/ {
        root /var/www/html;  # 该路径存放验证文件
    }

    location / {
        return 301 https://$host$request_uri;  # 强制 HTTPS
    }
}

4.生成 SSL 证书

运行以下命令来申请 SSL 证书:

对于 Nginx:

sudo certbot --nginx -d domain.com -d www.domain.com

对于 Apache:

sudo certbot --apache -d domain.com -d www.domain.com

5.设置自动续期

Let's Encrypt 的证书有效期为 90 天。可以通过以下命令测试续期:

sudo certbot renew --dry-run

本人 亲测 nginx的 成功。

使用 cat /etc/os-release 查看系统环境


本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表