nginx-ingress用注解设置wss,keepalive-timeout

通过nginx.ingress.kubernetes.io/configuration-snippet配置
nginx.ingress.kubernetes.io/configuration-snippet: |-
       proxy_set_header Upgrade "websocket";
       proxy_set_header Connection "Upgrade";
nginx.ingress.kubernetes.io/backend-protocol配置后端协议
例:
nginx.ingress.kubernetes.io/backend-protocol: FCGI
    #添加特殊配置片段
    nginx.ingress.kubernetes.io/configuration-snippet: keepalive_timeout  0;
    #关闭ssl强制跳转
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/enable-cors: "true"
    nginx.ingress.kubernetes.io/enable-modsecurity: "true"
    nginx.ingress.kubernetes.io/enable-owasp-core-rules: "true"
    nginx.ingress.kubernetes.io/server-snippet: keepalive_timeout  0;
    nginx.ingress.kubernetes.io/ssl-redirect: "false"

配置重写规则

$ echo '
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
 annotations:
   nginx.ingress.kubernetes.io/rewrite-target: /$2
 name: rewrite
 namespace: default
spec:
 rules:
 - host: rewrite.bar.com
   http:
     paths:
     - backend:
         serviceName: http-svc
         servicePort: 80
       path: /something(/|$)(.*)
' | kubectl create -f -

在此入口定义中,捕获的任何字符(.*)都将分配给占位符$2,然后将其用作rewrite-target注释中的参数。

例如,上面的入口定义将导致以下重写:

rewrite.bar.com/something 重写为 rewrite.bar.com/
rewrite.bar.com/something/ 重写为 rewrite.bar.com/
rewrite.bar.com/something/new 重写为 rewrite.bar.com/new

ingress-nginx官网说明链接: link.

Logo

开源、云原生的融合云平台

更多推荐