resource "aws_lb_listener_rule" "redirect_http_to_https" {
listener_arn = aws_lb_listener.front_end.arn
action {
type = "redirect"
redirect {
port = "443"
protocol = "HTTPS"
status_code = "HTTP_301"
}
}
condition {
path_pattern {
values = ["/health", "/status"]
}
}
}
此示例将重定向规则添加到ALB Listener中,将HTTP请求重定向到HTTPS。同时,该规则仅针对路径以“/health”或“/status”开头的请求执行重定向。