当前位置: 首页 > 帮助中心

Ubuntu域名如何进行SSL证书安装

时间:2026-01-29 15:00:24

在Ubuntu上为域名安装SSL证书的步骤如下:

安装Certbot和Web服务器软件

如果你使用的是Apache:

    更新包列表:
    sudo apt update
    安装Certbot和Apache模块:
    sudo apt install certbot python3-certbot-apache

如果你使用的是Nginx:

    更新包列表:
    sudo apt update
    安装Certbot和Nginx模块:
    sudo apt install certbot python3-certbot-nginx
获取证书

使用Certbot获取证书。根据你使用的服务器类型,运行以下命令之一:

对于Apache:

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

对于Nginx:

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

按照提示完成证书的获取过程。Certbot会自动配置Apache或Nginx以使用新获取的证书。

配置Web服务器对于Apache:

Certbot会自动修改配置文件(通常位于 /etc/apache2/sites-available/yourdomain.com-le-ssl.conf 或类似位置),确保以下内容存在:

<VirtualHost *:443>ServerAdmin webmaster@localhostDocumentRoot /var/www/htmlSSLEngine onSSLCertificateFile /etc/letsencrypt/live/yourdomain.com/fullchain.pemSSLCertificateKeyFile /etc/letsencrypt/live/yourdomain.com/privkey.pemInclude /etc/letsencrypt/options-ssl-apache.conf</VirtualHost>

启用SSL站点:

sudo a2ensite yourdomain.com-le-ssl.confsudo systemctl restart apache2
对于Nginx:

Certbot会自动修改配置文件(通常位于 /etc/nginx/sites-available/yourdomain.com 或类似位置),确保以下内容存在:

server {listen 443 ssl;server_name yourdomain.com;ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;include /etc/letsencrypt/options-ssl-nginx.conf;ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;root /var/www/html;index index.html index.htm;location / {try_files $uri $uri/ =404;}}

启用SSL站点:

sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/sudo nginx -tsudo systemctl restart nginx
测试配置

打开浏览器并访问 https://yourdomain.com,确保HTTPS连接正常,并且浏览器显示安全锁标志。

自动续期

Let’s Encrypt证书的有效期为90天。为了确保证书始终有效,你可以配置Certbot定期自动更新它们。例如,可以设置一个cron作业来自动执行证书更新:

sudo crontab -e

然后在打开的编辑器中添加以下行(确保将 /etc/letsencrypt/live/ 替换为你的实际证书路径):

0 0,12 * * * certbot renew --quiet && systemctl reload nginx

这将在每天执行两次证书更新检查。如果证书需要更新,Certbot将自动更新它们并重新加载Nginx服务。


上一篇:虚拟机ubuntu如何设置开机自启
下一篇:如何通过JS日志监控Debian服务器状态
Ubuntu
  • 英特尔与 Vertiv 合作开发液冷 AI 处理器
  • 英特尔第五代 Xeon CPU 来了:详细信息和行业反应
  • 由于云计算放缓引发扩张担忧,甲骨文股价暴跌
  • Web开发状况报告详细介绍可组合架构的优点
  • 如何使用 PowerShell 的 Get-Date Cmdlet 创建时间戳
  • 美光在数据中心需求增长后给出了强有力的预测
  • 2027服务器市场价值将接近1960亿美元
  • 生成式人工智能的下一步是什么?
  • 分享在外部存储上安装Ubuntu的5种方法技巧
  • 全球数据中心发展的关键考虑因素
  • 英特尔与 Vertiv 合作开发液冷 AI 处理器

    英特尔第五代 Xeon CPU 来了:详细信息和行业反应

    由于云计算放缓引发扩张担忧,甲骨文股价暴跌

    Web开发状况报告详细介绍可组合架构的优点

    如何使用 PowerShell 的 Get-Date Cmdlet 创建时间戳

    美光在数据中心需求增长后给出了强有力的预测

    2027服务器市场价值将接近1960亿美元

    生成式人工智能的下一步是什么?

    分享在外部存储上安装Ubuntu的5种方法技巧

    全球数据中心发展的关键考虑因素