回答
收藏
分享
举报
從Nginx往Nginx Ingress Controller遷移時Map的使用
提问于2021-06-19 17:06

浏览 689

現在使用的Nginx使用了根據Cookie裏面的一個字段來RewiriteURL。 往 Nginx Ingress Controller遷移後,有沒有類似簡單的寫法。

現有的Nginx定義

    map $cookie_target $subpath {
        1 subpath1;
        2 subpath2;
        3 subpath3;
        ・・・
        default subpathdefault;
    }
    server {
        location / {
            rewrite ^(.{5})(.*)$ http://www.example.com/$1/$subpath/$2 break;
        }}


現在找到的對應案, 大約有70個Cookie的種類  只能老老實實寫70個conditions麽?


apiVersion: k8s.nginx.org/v1
kind: VirtualServer
metadata:
name: cafe
spec:
host: cafe.example.com
upstreams:
- name: coffee
service: coffee-svc
port: 80
- name: tea
service: tea-svc
port: 80
routes:
- path: /(.{5})(.*)
matches:
- conditions:
- cookie: target
value: 1
action:
proxy:
upstream: coffee
rewritePath: http://www.example.com/$1/subpath1/$2
- conditions:
- cookie: target
value: 2
action:
proxy:
upstream: coffee
rewritePath: http://www.example.com/$1/subpath2/$2
・・・・・
action:
proxy:
upstream: coffee
rewritePath: http://www.example.com/$1/subpathdefault/$2


已修改于2023-03-09 02:23



写下您的回答
发表回答
全部回答(1)

按点赞数排序

按时间排序

建议采用configmap

赞同

0

回复举报

回答于2022-10-31 14:09



回复提桶跑路
回复
提问者
pl1751
这家伙很懒还未留下介绍~
0
文章
1
问答
0
粉丝
相关问答

这是一些监控的截图

点赞 0
浏览 819
可以和tomcat配合一起使用作为反向代理进行负载均衡配置
点赞 0
浏览 788