Ingress-nginx why location is different from same ingress file?

Stini

I am using ingress-nginx in my GKE cluster to expose my services. I have 2 different GKE cluster (v1.19.12-gke.2101) that both use ingress-nginx (chart v4.0.6).

On those cluster, I expose some services with a oauth-proxy. It works perfectly on the first cluster, but it doesn't on the second one with a 404 on the path /test/. I have been investigating a long time without finding what could cause this issue. The main difference I have found is in the nginx.conf file where the location differs. Here is the difference :

First cluster (working):

location ~* "^/test(/|$)(.*)/" {

Second cluster (not working):

location /test(/|$)(.*)/ {

Here is the ingress used for this line :

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/auth-url: "<auth-url>"
    nginx.ingress.kubernetes.io/auth-signin: "<auth-signin>"
    nginx.ingress.kubernetes.io/auth-realm: 'Authentication Required'
    kubernetes.io/tls-acme: 'true'
    ingress.kubernetes.io/force-ssl-redirect: 'true'
    nginx.ingress.kubernetes.io/proxy-body-size: 500m
    cert-manager.io/cluster-issuer: "letsencrypt-prod-dns01"
  name: service-oauth
  namespace: default
spec:
  rules:
  - host: "test.com"
    http:
      paths:
      - path: "/test(/|$)(.*)"
        pathType: ImplementationSpecific
        backend:
          service:
            name: test
            port:
              number: 1234
  ingressClassName: nginx
  tls:
  - secretName: test-tls
    hosts:
      - "test.com"

I have checked all my configuration files (ingress, services) without finding any differences. If you have any idea where the problem could come from, let me know.

Thanks for your help.

AndD

You are missing the annotation that enables regex, which is:

nginx.ingress.kubernetes.io/use-regex: "true"

You can test if this is the problem by going to the url:

test.com/test(/|$)(.*)

and check if a different NGINX answers you (oauth proxy) and if NGINX is logging something different (should log a forward of the request to the right service)


As for why it is working on the first cluster.. did you enable regex (or use rewrite target) for the same host but on another ingress?

I noticed this behaviour as well once.. with an ingress without this annotation (and without rewrite-target annotation as well) working perfectly fine while it shouldn't.. and I am quite sure it was because there were other ingresses for the same host which specified the use regex anotation.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

nginx-ingress session affinity behavior when ingress maps to 2 different ports on the same service

nginx ingress controller returns fake certificate for one ingress, but the right certificate for another ingress, both ingress are almost the same

routing wildcard domain to different paths in nginx ingress

forward from ingress nginx controller to different nginx pods according to port numbers

Kubernetes Nginx Ingress file upload returning 502

Ingress Resource getting address from wrong Ingress Controller when using multiple ingress-nginx Controllers

Kubernetes Ingress: Why I get different results for same configuration, but different hosts?

ingress nginx redirect from www to https

serving static files from ingress-nginx

Many different hosts in Ingress configuration file

How can I config the same behavior in nginx ingress controller as in nginx?

Securing specific nginx-ingress location with client cert verification

Nginx ingress controller modsecurity

Kubernetes with 2 ingress (nginx)

Ingress nginx cache

Rewriting issue with ingress nginx

Nginx ingress not redirecting to https

Keycloak redirect nginx ingress

Equivalents of Nginx Ingress Annonations on IstIO Ingress Gateway

Installing multiple nginx ingress controller instances in the same AKS cluster

Unable to add multiple Ingresses with same host on nginx-ingress

Kubernetes NGINX Ingress controller - different route if query string exists

Kubernetes nginx ingress can't access pod in different namespace

Why does nginx return 404 on my Kubernetes Ingress route?

Why does nginx return 404 on my Kubernetes Ingress route?

Why is my Nginx Ingress controller giving 503s?

ingress-nginx-controller-admission: what does it do? Why is it there

Setup two ingress for two services with same names in different namespaces

How to access MySql hosted with Nginx Ingress+Kubernetes from client

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    pump.io port in URL

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    flutter: dropdown item programmatically unselect problem

  14. 14

    How to use merge windows unallocated space into Ubuntu using GParted?

  15. 15

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  16. 16

    Nuget add packages gives access denied errors

  17. 17

    Svchost high CPU from Microsoft.BingWeather app errors

  18. 18

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  19. 19

    12.04.3--- Dconf Editor won't show com>canonical>unity option

  20. 20

    Any way to remove trailing whitespace *FOR EDITED* lines in Eclipse [for Java]?

  21. 21

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

HotTag

Archive