AWS新控制台中没有“Load Balancer Redirect”选项。相反,您可以使用以下代码示例创建一个重定向规则:
resource "aws_lb_listener_rule" "redirect_http_to_https" {
listener_arn = aws_lb_listener.front_end_https.arn
priority = 1
action {
type = "redirect"
redirect {
protocol = "HTTPS"
port = "443"
status_code = "HTTP_301"
}
}
condition {
field = "host-header"
values = ["example.com"]
}
}
此示例创建一个负载均衡器的监听器规则,将HTTP请求重定向到HTTPS,并返回HTTP 301状态代码。当主机头为“example.com”时,此规则将应用于请求。只需将“values”参数替换为您自己的域名列表即可。