在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 或类似位置),确保以下内容存在:
:443 >
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/yourdomain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/yourdomain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
启用SSL站点:
sudo a2ensite yourdomain.com-le-ssl.conf
sudo 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 -t
sudo 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域名如何进行SSL证书安装”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm