nginx - 将通配符域路由到 nginx 入口中的不同路径
问题描述
我如何实现与此类似的东西。
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
ingress.kubernetes.io/rewrite-target: /c/{word-maching-wildcard}
name: some-route
namespace: prod
spec:
rules:
- host: "*.example.com" # {hello}.example.com -> hello.example.com/hello
http:
paths:
- backend:
serviceName: svc
servicePort: 8080
path: /
有什么方法可以捕获子域中的匹配词,并在路由到上游服务之前将其附加到路径中。
解决方案
来自官方文档:
spec.rules.host
该字段不支持正则表达式和通配符 。必须使用完整的主机名。
但是我发现了类似的问题,建议编写自己的控制器,写出$http_host
在适当proxy_pass
或重定向行中使用的 nginx 配置。
阅读更多:通配符网址映射。
推荐阅读
- amazon-web-services - aws ECS,ECS 实例未注册到 ALB 目标组
- android - 应用程序正常运行,但单击注销按钮时崩溃
- java - 为什么 counter 是 double 而不是 long?
- javascript - 提交数据 Express 时附加多个 JSON 条目
- python - 如何使用 BeautifulSoup 抓取超链接标题?
- sonos - 有声读物的自测支持
- svg - 如何在 apache Royale 中使用图形 svg 元素?
- javascript - : 和 :? 的区别
- django - Django:如何在两个FormFields之间验证/验证一个“更大的”?
- go - 如何在不出现死锁错误的情况下获得所有结果