AWS负载均衡器的行为检查器默认会在http到https的301重定向中添加:80到URL中,这可能会导致问题。可以通过以下代码示例来禁用这种行为:
resource "aws_lb" "example" {
...
enable_deletion_protection = true
load_balancer_type = "application"
name = "example"
internal = false
access_logs {
...
enabled = false
}
subnets = ["subnet-12345678", "subnet-87654321"]
security_groups = ["sg-12345678"]
idle_timeout = 60
enable_http2 = false
ip_address_type = "ipv4"
tags = {
Name = "example"
}
}
resource "aws_lb_listener" "example" {
...
default_action {
...
redirect {
...
port = "443"
protocol = "HTTPS"
status_code = "HTTP_301"
}
}
}
resource "aws_lb_target_group" "example" {
...
target_type = "instance"
}
在以上代码示例中,通过将enable_http2
设置为false,可以禁用HTTP/2。这样,AWS负载均衡器在http到https的301重定向中就不会添加:80到URL中了。