You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

旧Play Framework应用:Pound+Let’s Encrypt与AWS CloudFront适配咨询

针对你的旧版Play Framework + Pound SSL端点 + AWS CloudFront CDN架构,替换Symantec通配符证书为Let’s Encrypt证书的配置方案如下,我分步骤给你拆解:

1. 获取Let’s Encrypt通配符证书

因为你需要覆盖主域名和两个CDN子域名(siteassets、courseassets),通配符证书是最优选择,这里用Certbot的DNS验证方式(支持通配符证书的标准验证方式):

  • 先在你的虚拟机上安装Certbot:
    如果你用Debian/Ubuntu:sudo apt update && sudo apt install certbot
    如果你用CentOS/RHEL:sudo yum install certbot
  • 生成通配符证书,执行命令:
    certbot certonly --manual --preferred-challenges dns -d *.yourdomain.com -d yourdomain.com
    
    跟着提示操作:需要在你的域名解析服务商处添加一条DNS TXT记录,验证完成后,Certbot会把证书文件存放在/etc/letsencrypt/live/yourdomain.com/目录下,关键文件包括:
    • fullchain.pem:包含服务器证书+中间证书的完整证书链
    • privkey.pem:证书对应的私钥文件
2. 配置Pound使用新证书

Pound作为你的SSL终止端点,需要修改配置文件指向Let’s Encrypt的证书:

  • 找到Pound的配置文件(通常是/etc/pound/pound.cfg,不同系统可能略有差异),定位到原有的ListenHTTPS段:

    ListenHTTPS
    Address 0.0.0.0
    Port 443
    Cert "/path/to/old/symantec-wildcard.crt"
    Service
    BackEnd
    Address 127.0.0.1
    Port 9000
    End
    End
    End

  • 修改证书和私钥路径,替换为Let’s Encrypt的文件:
    ListenHTTPS
        Address 0.0.0.0
        Port    443
        # 注意:部分旧版Pound需要同时指定Cert和Key,或者合并成单个文件
        Cert    "/etc/letsencrypt/live/yourdomain.com/fullchain.pem"
        Key     "/etc/letsencrypt/live/yourdomain.com/privkey.pem"
        # 保留原有的Backend指向Play应用的9000端口配置
        Service
            BackEnd
                Address 127.0.0.1
                Port    9000
            End
        End
    End
    
  • 注意:如果旧版Pound不支持分开指定Cert和Key,你可以合并证书和私钥成一个文件:
    sudo cat /etc/letsencrypt/live/yourdomain.com/privkey.pem /etc/letsencrypt/live/yourdomain.com/fullchain.pem > /etc/pound/letsencrypt-combined.pem
    
    然后把配置里的Cert指向这个合并后的文件即可。
  • 重启Pound服务让配置生效:
    sudo systemctl restart pound
    # 或者旧版系统用:sudo service pound restart
    
    sudo systemctl status pound检查服务是否正常启动,确保没有证书加载错误。
3. 更新AWS CloudFront CDN的证书配置

你的两个CloudFront分发(siteassets、courseassets)需要更新为新的Let’s Encrypt证书:

  • 先把Let’s Encrypt证书导入AWS Certificate Manager(ACM):
    1. 登录AWS控制台,进入ACM服务,注意必须选择us-east-1区域(因为CloudFront仅支持该区域的ACM证书)
    2. 点击"导入证书",分别粘贴:
      • 证书正文:/etc/letsencrypt/live/yourdomain.com/fullchain.pem里的内容
      • 私钥:/etc/letsencrypt/live/yourdomain.com/privkey.pem里的内容
      • 证书链:可以直接用fullchain.pem里的中间证书,或者单独用/etc/letsencrypt/live/yourdomain.com/chain.pem的内容
  • 分别更新两个CloudFront分发:
    1. 进入CloudFront控制台,找到对应的分发(siteassets、courseassets),点击"编辑"
    2. 在"SSL证书"选项中,选择刚才导入的Let’s Encrypt通配符证书
    3. 保持原有的"查看协议"、"缓存策略"等配置不变,保存更改
    4. 等待CloudFront部署完成(通常需要15-30分钟)
4. 验证与自动续期
  • 验证配置:访问你的Play应用和CDN资源,在浏览器地址栏点击锁形图标,确认证书颁发机构是Let’s Encrypt,且覆盖对应的域名
  • 配置证书自动续期:Let’s Encrypt证书有效期为90天,设置自动续期避免过期:
    1. 先测试续期流程:sudo certbot renew --dry-run,确保没有报错
    2. 设置自动续期的定时任务,比如添加cron任务:
      sudo crontab -e
      
      添加一行:
      0 3 * * * /usr/bin/certbot renew --quiet --deploy-hook "sudo systemctl restart pound"
      
      这条命令会每天凌晨3点尝试续期,续期成功后自动重启Pound加载新证书。

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

火山引擎 最新活动