阅读量:4
在Ubuntu上配置SSL证书,一般可按以下步骤进行:
准备工作
更新系统软件包并安装必要的依赖,如OpenSSL:
sudo apt update
sudo apt install openssl
获取SSL证书
可使用Let’s Encrypt免费获取,安装Certbot工具:
sudo apt install certbot python3-certbot-nginx # 用于Nginx
sudo apt install certbot python3-certbot-apache # 用于Apache
然后运行Certbot获取证书,以Nginx为例:
sudo certbot --nginx -d example.com -d www.example.com
配置Web服务器
- Nginx:Certbot会自动修改配置文件,通常位于
/etc/nginx/sites-available/。确保配置中包含监听443端口、指定证书和私钥文件路径等内容,如:
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
# 其他配置...
}
修改后测试配置并重新加载Nginx:
sudo nginx -t
sudo systemctl reload nginx
- Apache:Certbot会自动更新虚拟主机配置文件,一般在
/etc/apache2/sites-available/。确保包含类似以下内容:
:443 >
ServerName example.com
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
# 其他配置...
然后启用站点并重启Apache:
sudo a2ensite example.com.conf
sudo systemctl restart apache2
设置自动续期
Let’s Encrypt证书有效期为90天,Certbot可自动续期。可手动测试续期:
sudo certbot renew --dry-run
若要设置定时任务自动续期,可编辑crontab:
sudo crontab -e
添加如下内容(每天检查两次):
0 12 * * * /usr/bin/certbot renew --quiet
0 0 * * * /usr/bin/certbot renew --quiet
以上就是关于“怎样在Ubuntu上配置SSL证书”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm