禁止默认规则:禁用ALB中的默认规则,强制所有流量显式地定义其要使用的规则。
增加拒绝规则:添加一个拒绝规则,以确保任何未定义规则的流量都被拒绝。
示例代码:
#禁止默认规则 resource "aws_alb" "example" { name = "example" security_groups = [aws_security_group.example.id] subnets = aws_subnet.example.*.id internal = false enable_deletion_protection = false load_balancer_type = "application" tags = { Terraform = "true", Environment = "dev", } enable_http2 = true
default_action { type = "forward" target_group_arn = aws_lb_target_group.example.arn }
lifecycle { create_before_destroy = true } }
#添加拒绝规则 resource "aws_alb_listener_rule" "reject" { listener_arn = aws_alb_listener.example.arn priority = "1"
action { type = "fixed-response" status_code = "403" content_type = "text/plain" message_body = "Access Denied" }
condition { path_pattern { values = ["/"] } } }
上一篇:ALB没有正确传播响应头