google-cloud-platform - GCP url map 为不同的后端服务创建路径规则
问题描述
下面是我的地形脚本。我已经设置了必要的转发规则和目标 http 代理。后端服务也存在。我可以访问 下的所有路径/images/*
,但是,我无法访问 下的路径/videos/*
。从脚本来看,默认后端服务是backend-lb-prod
路径所在的后端服务/images/*
。我将默认后端服务切换为backend-lb
,我现在可以访问/videos/*
但不能访问/images/*
。
resource "google_compute_url_map" "url-map-be" {
name = "${var.platform_name}-url-map-be-prod"
default_service = "${google_compute_backend_service.backend-lb-prod.self_link}"
host_rule {
hosts = ["${var.backend_address_name}"]
path_matcher = "allpaths"
}
path_matcher {
name = "allpaths"
default_service = "${google_compute_backend_service.backend-lb-prod.self_link}"
path_rule {
paths = [“/images"]
service = "${google_compute_backend_service.backend-lb-prod.self_link}"
}
path_rule {
paths = [“/images/*"]
service = "${google_compute_backend_service.backend-lb-prod.self_link}"
}
path_rule {
paths = ["/videos"]
service = "${google_compute_backend_service.backend-lb.self_link}"
}
path_rule {
paths = ["/videos/*"]
service = "${google_compute_backend_service.backend-lb.self_link}"
}
}
}
当我在谷歌控制台上运行 url 映射的测试时,这是我得到的错误
Invalid value for field 'resource': ''. Test failure: Expect URL ‘*.*.*.*/videos/go'
to map to service ‘***93-BACKEND_SERVICE-**-backend-lb', but actually mapped to
'***93-BACKEND_SERVICE-**-backend-lb-prod’.
这就是google_compute_url_map
terraform文档中的说明方式。在这种情况下我错过了什么。
更新
我已经包含了/videos
和/images
路径,上面的错误消失了。但是,从应用程序的日志来看,流量仍然是通过默认的后端服务发送的。
解决方案
希望这对其他人有帮助。最初host_rule
是hosts
一个 IP 地址。我也将其更改为域名,但它仍将所有流量发送到默认后端服务。我将其更改为*
现在可以按预期工作。还要注意的是,不是默认后端服务的路径需要几分钟才能访问。
host_rule {
hosts = ["*"]
path_matcher = "allpaths"
}
推荐阅读
- java - Dockerfile COPY failed: stat no such file, when using GitHub CI
- reactjs - 如何在 Redux 中管理嵌套的 reducer?
- c - 根据文件中的行创建数组
- uwp - 使用连续听写
- reactjs - 如何使用命令提示符检查当前版本的 React
- sql - sql中的nameUUIDFromBytes
- lambda - 返回 lambda 函数与在 python 装饰器中返回方法的区别
- swift - 当我滚动时,TableView DidSelectRowAt 将更改其他单元格的背景颜色
- sql-server - 在字符串中捕获字符串
- php - 在 Laravel 中返回数据库查询时更改字段值