在Ubuntu上配置Apache以使用SSL证书,可以按照以下步骤进行:
1. 安装Apache和SSL模块
首先,确保你已经安装了Apache和SSL模块。你可以使用以下命令来安装它们:
sudo apt update
sudo apt install apache2
sudo apt install apache2-mod_ssl
2. 获取SSL证书
你可以从Let’s Encrypt免费获取SSL证书,或者购买一个商业证书。以下是使用Let’s Encrypt的步骤:
使用Certbot获取证书
Certbot是一个自动化的工具,可以帮助你获取和续订Let’s Encrypt证书。
-
安装Certbot:
sudo apt install certbot python3-certbot-apache -
运行Certbot来获取证书:
sudo certbot --apacheCertbot会引导你完成以下步骤:
- 选择是否重定向所有HTTP流量到HTTPS。
- 输入你的域名。
- 验证你对域名的控制权(通常是通过HTTP-01挑战)。
- 输入电子邮件地址(用于接收证书续订通知)。
- 同意条款和条件。
3. 配置Apache虚拟主机
Certbot会自动为你创建一个SSL虚拟主机配置文件。你可以在/etc/apache2/sites-available/目录下找到这个文件,通常命名为yourdomain.com-le-ssl.conf。
你可以编辑这个文件来进一步自定义你的SSL配置。例如:
:443 >
ServerAdmin webmaster@yourdomain.com
ServerName yourdomain.com
ServerAlias www.yourdomain.com
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
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
4. 启用SSL虚拟主机
确保你的SSL虚拟主机配置文件已启用:
sudo a2ensite yourdomain.com-le-ssl.conf
然后重新加载Apache服务以应用更改:
sudo systemctl reload apache2
5. 测试SSL配置
打开浏览器并访问你的域名,确保它通过HTTPS提供服务,并且浏览器显示安全锁标志。
6. 自动续订证书
Let’s Encrypt证书通常每90天过期一次。Certbot会自动处理续订过程,但你需要确保cron任务已设置:
sudo systemctl status certbot.timer
如果没有运行,可以启动并启用它:
sudo systemctl start certbot.timer
sudo systemctl enable certbot.timer
通过以上步骤,你应该能够在Ubuntu上成功配置Apache以使用SSL证书。
以上就是关于“Ubuntu Apache怎样配置SSL证书”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm