Score:0

wildcard url in ingress-nginx kubernetes Ingress to redirect to path based url doesn't seem to pass regex value

ke flag

Trying to setup a wildcard url in ingress-nginx kubernetes Ingress to redirect to path based url it doesn't seem to pass the wildcard regex value.

The url would be something like "https://test.dev.example1.com/admin" and it should redirect to https://example2.com/folder/test

The result I am getting is redirect to https://example2.com/folder/

It appears I am not getting the wildcard value of "test" coming thru as a variable

Below is a snippet of the Ingress

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
   name: sample-service-ingress
   annotations:
     kubernetes.io/ingress.class: nginx
     cert-manager.io/issuer: "letsencrypt-production"
     nginx.ingress.kubernetes.io/ssl-redirect: "true"
     nginx.ingress.kubernetes.io/server-snippet: |
        server_name ~^(?<name>[\w-]+)\.dev\.example1\.com$;

        location /admin {
          return 301 $scheme://example2.com/folder/$name;

        }
...

I have also tested the regex in regex101.com and it looks to be correct. (minus the ~)

I have tried a few things like taking the $name var and putting in the middle of two other hardcoded values (ex. return 301 $scheme://example2.com/folder/begin.$name.end;) which returns "https://example2.com/folder/begin..end" which returns an empty or NULL value in between the begin..end hard coded values.

I am unsure if the $name var in the regex is correctly passing. I am not able to see a value.

I have used this in reference to the following as a reference https://stackoverflow.com/questions/39563071/how-to-get-subdomain-of-url-in-nginx

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.