Ingress Nginx 在服务器片段中使用正则表达式
Ingress Nginx use regex in Server snippet
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/auth-method: POST
nginx.ingress.kubernetes.io/auth-response-headers: id
nginx.ingress.kubernetes.io/auth-url: http://auth.default.svc.cluster.local:8000/authenticate
nginx.ingress.kubernetes.io/configuration-snippet: error_page 401 /error/401;
error_page 403 /error/403;
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/server-snippet: location = /fhir/{
auth_request /auth/; auth_request_set $id $upstream_http_id;
proxy_pass http://pth-auth.default.svc.cluster.local:8000/authenticate; proxy_set_header x-tenant-id $id;
proxy_method POST; error_page 401 /error/401; error_page 403 /error/403;} location = /error/401 { proxy_method
POST; proxy_pass http://auth.default.svc.cluster.local:8000/error/401; }
location = /error/403 { proxy_method POST; proxy_pass http://auth.default.svc.cluster.local:8000/error/403;
} location = /auth/ { proxy_pass http://auth.default.svc.cluster.local:8000/authenticate; proxy_method POST;
proxy_set_header x-original-method $request_method; proxy_set_header x-original-uri $request_uri;}
nginx.ingress.kubernetes.io/use-regex: 'true'
name: ingress-nginx
spec:
rules:
- http:
paths:
- path: /?(.*)
backend:
serviceName: xyz
servicePort: 80
在 location = /fhir/ 的服务器片段中,我想匹配具有 /fhir/(.*) 的任何模式,但我无法为此找到任何好的解决方案。目前它作为精确匹配工作。
这对我有用
location ~* "^/fhir/.*" {无论你想在这里写什么}
这将匹配任何具有前缀 fhir.Took 引用的内容 https://kubernetes.github.io/ingress-nginx/user-guide/ingress-path-matching/
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/auth-method: POST
nginx.ingress.kubernetes.io/auth-response-headers: id
nginx.ingress.kubernetes.io/auth-url: http://auth.default.svc.cluster.local:8000/authenticate
nginx.ingress.kubernetes.io/configuration-snippet: error_page 401 /error/401;
error_page 403 /error/403;
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/server-snippet: location = /fhir/{
auth_request /auth/; auth_request_set $id $upstream_http_id;
proxy_pass http://pth-auth.default.svc.cluster.local:8000/authenticate; proxy_set_header x-tenant-id $id;
proxy_method POST; error_page 401 /error/401; error_page 403 /error/403;} location = /error/401 { proxy_method
POST; proxy_pass http://auth.default.svc.cluster.local:8000/error/401; }
location = /error/403 { proxy_method POST; proxy_pass http://auth.default.svc.cluster.local:8000/error/403;
} location = /auth/ { proxy_pass http://auth.default.svc.cluster.local:8000/authenticate; proxy_method POST;
proxy_set_header x-original-method $request_method; proxy_set_header x-original-uri $request_uri;}
nginx.ingress.kubernetes.io/use-regex: 'true'
name: ingress-nginx
spec:
rules:
- http:
paths:
- path: /?(.*)
backend:
serviceName: xyz
servicePort: 80
在 location = /fhir/ 的服务器片段中,我想匹配具有 /fhir/(.*) 的任何模式,但我无法为此找到任何好的解决方案。目前它作为精确匹配工作。
这对我有用 location ~* "^/fhir/.*" {无论你想在这里写什么} 这将匹配任何具有前缀 fhir.Took 引用的内容 https://kubernetes.github.io/ingress-nginx/user-guide/ingress-path-matching/