|NO.Z.00356|——————————|CloudNative|——|KuberNetes&運維.V72|-----------------------------------------------------------|IngressNginx.v08|匹配請求頭|
阿新 • • 發佈:2022-04-01
[CloudNative:KuberNetes&運維.V72] [Applications.KuberNetes] [|DevOps|k8s|k8s運維|**3節點.V1**|IngressNginx匹配請求頭|]
一、IngressNginx匹配請求頭概述
二、IngressNginx匹配請求頭實驗### --- 匹配請求頭: ~~~ 可以根據不同的使用者,不同的客戶端分發到不同的後端服務 ~~~ 可以做一些灰度或者區分web端和手機端請求區別
三、通過瀏覽器訪問該域名:http://rewrite.test.com/:說明是可以正常訪問的### --- 配置ingress-block.yaml檔案 ~~~ 修改配置檔案 [root@k8s-master01 ~]# cat ingress-block.yaml apiVersion: networking.k8s.io/v1beta1 kind: Ingress metadata: annotations: nginx.ingress.kubernetes.io/rewrite-target: /$2 nginx.ingress.kubernetes.io/server-snippet: |2- set $agentflag 0; if ($http_user_agent ~* "(iPhone)" ){ set $agentflag 1; } if ( $agentflag = 1 ) { return 301 https://www.baidu.com; } name: ingress-test namespace: ratel-test1 spec: rules: - host: rewrite.test.com http: paths: - backend: serviceName: ingress-test servicePort: 80 path: /something(/|$)(.*) pathType: ImplementationSpecific
### --- 通過瀏覽器訪問該域名:http://rewrite.test.com/:說明是可以正常訪問的
~~~ ——>F12——>ctrl+shift+M:選擇裝置型別:iPhonex——>重新整理
~~~ ——>重新整理後匹配了請求頭,是iPhone就跳轉到百度
===============================END===============================
Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart ——W.S.Landor
來自為知筆記(Wiz)