ubuntu

ubuntu nginx ssl证书怎么安装

小樊
41
2025-09-09 06:05:32
栏目: 云计算

在Ubuntu上安装Nginx的SSL证书,通常使用Let’s Encrypt免费证书,步骤如下:

  1. 安装Nginx和Certbot:执行sudo apt update,然后sudo apt install nginx certbot python3-certbot-nginx
  2. 获取SSL证书:用sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com命令获取证书,Certbot会自动配置Nginx。
  3. 手动配置(可选):若需手动配置,编辑/etc/nginx/sites-available/yourdomain.com,添加如下内容:
server {
    listen 443 ssl;
    server_name yourdomain.com www.yourdomain.com;
    ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers on;
    location / {
        root /var/www/html;
        index index.html index.htm;
    }
}
server {
    listen 80;
    server_name yourdomain.com www.yourdomain.com;
    return 301 https://$host$request_uri;
}
  1. 测试与重载:运行sudo nginx -t测试配置,无误后用sudo systemctl reload nginx重载Nginx。
  2. 自动续订:Certbot会自动设置定时任务续订证书,可用sudo certbot renew --dry-run测试。

0
看了该问题的人还看了