Lio*_*orH 3 terraform elastic-load-balancer
如果我做对了,lb_listener只接受forward作为有效的动作类型. https://www.terraform.io/docs/providers/aws/r/lb_listener.html 如何配置侦听器以将HTTP重定向到HTTPS?
即这是elb listener中所需的状态:
此功能已添加到AWS提供程序,并随1.33.0一起发布.
以下是使用aws_lb_listener资源在负载均衡器侦听器上设置默认操作的方法:
resource "aws_lb" "front_end" {
# ...
}
resource "aws_lb_listener" "front_end" {
load_balancer_arn = "${aws_lb.front_end.arn}"
port = "80"
protocol = "HTTP"
default_action {
type = "redirect"
redirect {
port = "443"
protocol = "HTTPS"
status_code = "HTTP_301"
}
}
}
Run Code Online (Sandbox Code Playgroud)
您还可以使用aws_lb_listener_rule资源中的各个负载均衡器侦听器规则添加重定向和固定类型响应:
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 {
field = "host-header"
values = ["my-service.*.terraform.io"]
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2782 次 |
| 最近记录: |