ingres nginx 反向代理常见配置(持续更新)

一、匹配到的location的关键字不传递给后端

如果想实现访问的url 匹配到的location,不携带给后端服务

类似nginx的配置如下

可以看到 proxy_pass http://chatbot_flask/; 后面是带了**"/"的,这代表反向代理给后端的upstream节点不携带"im_chat"**这个关键字.

假设我的请求是https://xxx.xxx.com/im_chat/v1/chat/create

当请求到达nginx时,nginx会将/v1/chat/create 这段url反向代理访问后端的节点

bash 复制代码
   location /im_chat {
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header X-Forwarded-Port $server_port;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://chatbot_flask/;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
            proxy_connect_timeout   60s;
            proxy_send_timeout      60s;
            proxy_read_timeout      60s;
            proxy_buffering off;
    }

重点来了对应的k8s ingress nginx 的配置如下:

bash 复制代码
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: chatbot
  namespace: bmm-system
  annotations:
    nginx.ingress.kubernetes.io/proxy-body-size: 100M
    nginx.ingress.kubernetes.io/proxy-connect-timeout: "600"
    nginx.ingress.kubernetes.io/proxy-next-upstream: error timeout http_500 http_502 http_503 http_504
    nginx.ingress.kubernetes.io/proxy-read-timeout: "600"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "600"
    nginx.ingress.kubernetes.io/use-regex: "true"
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  ingressClassName: "ingress-xxx-ext-nginx1"
  tls:
   - hosts:
     - xxx.xxx.cn
     secretName: xxx-tls
  rules:
    - host: xxx.xxx.cn
      http:
        paths:
          - pathType: ImplementationSpecific  
            backend:
              service:
                name: chatbot
                port:
                  number: 5001
            path: /im_chat(/|$)(.*)
相关推荐
GreenMountainEcho6 小时前
Kubernetes 入门篇之 Node 安装与部署
云原生·容器·kubernetes
ghostwritten8 小时前
Rancher Backup
kubernetes·rancher
alden_ygq9 小时前
k8s statefulset pod重启顺序
云原生·容器·kubernetes
ghostwritten9 小时前
k8s黑科技:Linux+Vagrant+VirtualBox开启Kubernetes奇幻之旅
linux·科技·kubernetes
云上艺旅11 小时前
K8S学习之基础七十二:Ingress基于Https代理pod
学习·云原生·容器·https·kubernetes
liux352812 小时前
k8s之Ingress讲解
云原生·容器·kubernetes
小刘爱喇石( ˝ᗢ̈˝ )15 小时前
玛卡巴卡的k8s知识点问答题(六)
云原生·容器·kubernetes
rider18916 小时前
【1】搭建k8s集群系列(二进制部署)之系统初始化
云原生·容器·kubernetes
小刘爱喇石( ˝ᗢ̈˝ )17 小时前
玛卡巴卡的k8s知识点问答题(七)
云原生·容器·kubernetes
小哈里19 小时前
【运维】云计算的发展历程,云原生时代的运维理念&工具技术栈,高可用系统的云运维 —— 以K8S集群调度算法与命令为例
运维·云原生·kubernetes·云计算·架构设计