You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为运行Ubuntu的EC2实例获取SSL证书?

Fixing SSL Certificate Setup for Ubuntu EC2 Instances

Got it, since you were following a tutorial for Amazon Linux 2 and it didn't work for your Ubuntu EC2 instance, let's walk through the correct steps tailored specifically for Ubuntu. I'll assume you're using Apache (since the original tutorial focused on Apache), but if you're on Nginx instead, just holler and I can adjust the steps!

Step 1: Update System Packages First

Start by making sure all your system packages are up-to-date to avoid compatibility hiccups:

sudo apt update && sudo apt upgrade -y

Step 2: Install Apache & Certbot (Let's Encrypt Tool)

We’ll use Certbot from Let’s Encrypt to get a free, trusted SSL certificate—it also automates most of the Apache configuration heavy lifting:

  • Install Apache if you haven’t already:
    sudo apt install apache2 -y
    
  • Install Certbot and its Apache plugin:
    sudo apt install certbot python3-certbot-apache -y
    

Step 3: Prep Apache for SSL

Enable the necessary Apache modules and restart the service to apply changes:

sudo a2enmod ssl rewrite
sudo systemctl restart apache2

Critical Check: Make sure your domain is already pointing to your EC2 instance’s public IP (or Elastic IP) via your DNS provider. Certbot needs this to verify you own the domain.

Step 4: Grab & Install the SSL Certificate

Run the Certbot Apache wizard—it handles certificate issuance and configures Apache to use HTTPS automatically:

sudo certbot --apache

Follow the on-screen prompts:

  • Enter a valid email for renewal alerts
  • Agree to Let’s Encrypt’s terms of service
  • Choose whether to share your email with the EFF (totally optional)
  • Pick the domain(s) you want to secure (double-check they match your DNS setup)

Once this finishes, your site should load over HTTPS right away!

Step 5: Verify Auto-Renewal

Let’s Encrypt certificates expire after 90 days, but Certbot sets up automatic renewal by default. Test that it works with:

sudo certbot renew --dry-run

If this runs without errors, you’re covered for auto-renewals.

Quick Troubleshooting

If HTTPS still isn’t working:

  • Double-check your EC2 security group allows inbound traffic on port 443 (HTTPS)
  • If you’re using Ubuntu’s ufw firewall, allow full Apache access:
    sudo ufw allow 'Apache Full'
    

内容的提问来源于stack exchange,提问作者user8959559

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 09:23:42