|NO.Z.00356|——————————|CloudNative|——|KuberNetes&运维.V72|——|IngressNginx.v08|匹配请求头|

一、IngressNginx匹配请求头概述
### --- 匹配请求头:

~~~     可以根据不同的用户,不同的客户端分发到不同的后端服务
~~~     可以做一些灰度或者区分web端和手机端请求区别
二、IngressNginx匹配请求头实验
### --- 配置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/:说明是可以正常访问的
### --- 通过浏览器访问该域名:http://rewrite.test.com/:说明是可以正常访问的

~~~     ——>F12——>ctrl+shift+M:选择设备类型:iPhonex——>刷新
~~~     ——>刷新后匹配了请求头,是iPhone就跳转到百度

 
 
 
 
 
 
 
 
 

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

 

 

posted on   yanqi_vip  阅读(46)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示