ubuntu

Apache2在Ubuntu上如何启用SSL

小樊
38
2025-04-20 06:37:32
栏目: 云计算

在Ubuntu上启用Apache2的SSL,你需要遵循以下步骤:

  1. 安装Apache2(如果尚未安装):
sudo apt update
sudo apt install apache2
  1. 安装Certbot(Certbot是一个自动获取和配置Let’s Encrypt SSL证书的工具):
sudo apt install certbot python3-certbot-apache
  1. 运行Certbot以获取SSL证书:
sudo certbot --apache
  1. Certbot将提示你输入电子邮件地址、同意服务条款以及选择证书存储位置。完成这些步骤后,Certbot将自动配置Apache2以使用SSL。

  2. Certbot将为你生成一个名为/etc/letsencrypt/options-ssl-apache.conf的文件,其中包含一些推荐的SSL设置。你可以将这些设置合并到你的主Apache配置文件(通常是/etc/apache2/apache2.conf/etc/apache2/sites-available/000-default.conf)中。

  3. 编辑你的Apache配置文件,确保包含以下内容:

Include /etc/letsencrypt/options-ssl-apache.conf
  1. 保存并关闭配置文件。

  2. 重启Apache2以应用更改:

sudo systemctl restart apache2

现在,你的网站应该已经通过HTTPS提供服务。你可以通过访问https://yourdomain.com来验证这一点。如果一切正常,浏览器将显示一个绿色的锁图标,表示连接已加密。

请注意,Let’s Encrypt证书的有效期为90天。为了确保证书始终有效,你可以使用Certbot的自动续订功能。Certbot将每天检查证书的有效期,并在证书即将过期时自动续订。

0
看了该问题的人还看了