Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
119 views
in Technique[技术] by (71.8m points)

nginx.ingress.kubernetes.io/rewrite-target can't regex capture url parameters

Recently I have setup an EKS cluster to run an application through ingress-nginx. I am trying to use regex capturing and nginx.ingress.kubernetes.io/rewrite-target to change my url parameters but it is not behaving as I'd expect it to behave. Here is my configuration which is

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    meta.helm.sh/release-name: sandbox1
    meta.helm.sh/release-namespace: sandbox1
    nginx.ingress.kubernetes.io/use-regex: "true"
    nginx.ingress.kubernetes.io/rewrite-target: /$1?$2
    nginx.ingress.kubernetes.io/enable-rewrite-log: "true"
  labels:
    app.kubernetes.io/component: api-gateway
    app.kubernetes.io/instance: sandbox1
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: api-gateway
    app.kubernetes.io/part-of: fusion
    app.kubernetes.io/version: "5"
    helm.sh/chart: api-gateway-1.8.0
  name: sandbox1-api-gateway
  namespace: sandbox1
spec:
  rules:
  - host: app.example.com
    http:
      paths:
      - backend:
          serviceName: proxy
          servicePort: 6764
        path: /(.*)?(.*)

If I do:

curl -i -k https://app.example.com/something/bla1/bla2?param1=a&param2=b

Rewrite logs show

"Basic.*" does not match ""

Something odd is going on here because if I change the configuration with path: /(.*)bla1(.*) and do the same curl request again the regex matches and the redirect occurs properly (as silly as this example is).

  • I wonder is the ? character not being matched properly ?
  • Is it not possible to manipulate url parameters using nginx.ingress.kubernetes.io/rewrite-target ?
  • Maybe I am missing something ?

Any help is welcomed, thanks.

question from:https://stackoverflow.com/questions/65923749/nginx-ingress-kubernetes-io-rewrite-target-cant-regex-capture-url-parameters

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...