浏览 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
按点赞数排序
按时间排序