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

Amazon Linux下Airflow HTTPS配置证书无效问题求助

解决EC2 Airflow HTTPS证书无效问题(免费适配IP变更方案)

方案1:Let's Encrypt免费证书+动态DNS(适配公网IP变动)

针对EC2每月重启可能换IP的情况,用动态DNS绑定域名+免费可信证书解决:

  • 注册免费动态DNS域名(如No-IP、DuckDNS),将EC2公网IP绑定到该域名。编写简单bash脚本,设置开机自动执行,每次EC2重启后自动更新域名的IP解析记录。
    • 脚本示例(以DuckDNS为例):
      #!/bin/bash
      DOMAIN="your-duckdns-domain"
      TOKEN="your-duckdns-token"
      IP=$(curl -s http://icanhazip.com)
      curl "https://www.duckdns.org/update?domains=$DOMAIN&token=$TOKEN&ip=$IP"
      
      把脚本保存为/usr/local/bin/update-dns.sh,添加执行权限sudo chmod +x /usr/local/bin/update-dns.sh,然后通过systemd或rc.local设置开机启动。
  • 安装certbot工具申请Let's Encrypt证书:
    • Amazon Linux 2:sudo yum install certbot python3-certbot-apache -y
    • Ubuntu/Debian:sudo apt install certbot python3-certbot-apache -y
    • 申请并自动配置证书:sudo certbot --apache -d your-dynamic-domain.duckdns.org,按提示完成操作,certbot会自动修改Httpd的SSL配置。
  • 设置证书自动续期:Let's Encrypt证书有效期90天,添加定时任务自动续期:
    • 编辑crontab:sudo crontab -e,添加行:0 12 * * * /usr/bin/certbot renew --quiet

方案2:优化自签证书(仅限个人/内部使用)

如果仅自己或内部团队访问,可生成带SAN扩展的自签证书,并手动让浏览器信任:

  • 生成带IP和DNS扩展的自签证书:
    1. 创建openssl配置文件/tmp/openssl.cnf:
    [req]
    distinguished_name = req_distinguished_name
    x509_extensions = v3_req
    prompt = no
    [req_distinguished_name]
    CN = EC2-Airflow
    [v3_req]
    keyUsage = keyEncipherment, dataEncipherment
    extendedKeyUsage = serverAuth
    subjectAltName = IP:你的EC2公网IP, DNS:localhost
    
    1. 生成证书和密钥:
    sudo openssl req -x509 -nodes -days 3650 -newkey rsa:2048 \
    -keyout /etc/httpd/conf.d/airflow.key \
    -out /etc/httpd/conf.d/airflow.crt \
    -config /tmp/openssl.cnf
    
  • 手动导入证书到浏览器:导出airflow.crt文件,在浏览器的证书管理中,将其添加到「受信任的根证书颁发机构」列表,之后访问就不会提示证书无效。

关键提醒

  • 动态DNS方案需确保EC2能访问外网,用于certbot的域名验证和DNS更新。
  • 自签证书方案仅适合非公开场景,对外访问不建议使用。
  • 若EC2重启后IP变更,动态DNS脚本必须确保能自动同步IP,否则证书会因域名解析不匹配失效。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.09 08:40:22