HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Nginx ingress controller redirects the url to /login

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
ingresstheloginnginxcontrollerredirectsurl

Problem

I am trying to access a url example.com/service/test1 but it redircts me to example.com/login.

Below is my YAMl file:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: test-ing
  namespace: test
  annotations:
     nginx.ingress.kubernetes.io/ssl-redirect: "false"
     nginx-ingress.kubernetes.io/use-regex: true

spec:
  rules:
  - host: example.com
    http:
      paths:
      - backend:
          serviceName: svc-test
          servicePort: 8080
        path: /service/test
  tls:
  - secretName: tls-secret

Solution

It just works

Your configuration is correct.

Provided YAML file generates nginx config like this:

...
server {
 listen       80;
 server_name  example.com;
 ...
 location ~* "^/service/test" {
   root    /var/www/example.com/htdocs;
 }
}


Testing this config via this cool tester shows that location filter works:

  • http://example.com/service/test1 -> Location: ^/service/test



  • http://example.com/service/test -> Location: ^/service/test



  • http://example.com/login -> Errors: No locations matched



For more details, see this explanation of Ingress Path Matching and examples from NGINX Docs:



  • Examples show how to use advanced NGINX features in Ingress resources with annotations.



  • Examples of Custom Resources show how to use VirtualServer and VirtualServerResources for a few use cases.




Check your app

Check your app, maybe it forward non-authorized requests to /login url.
You may use curl -v or wget, e.g:

curl -v -L http://example.com/service/test1 | egrep "^> (Host:|GET)"


wget  http://example.com/service/test1 2>&1 | grep Location


Howto debug nginx ingress

There is an Nginx debug mode for debugging nginx locations and redirects.
To enable it, use --v=5 in kubectl edit deploy.

See: k8s debug logging:


Using the flag --v=XX it is possible to increase the level of logging. This is performed by editing the deployment.

$ kubectl get deploy -n 
NAME                       DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
default-http-backend       1         1         1            1           35m
nginx-ingress-controller   1         1         1            1           35m

$ kubectl edit deploy -n  nginx-ingress-controller
# Add --v=X to "- args", where X is an integer






  • --v=2 shows details using diff about the changes in the configuration in nginx



  • --v=3 shows details about the service, Ingress rule, endpoint changes and it dumps the nginx configuration in JSON format



  • --v=5 configures NGINX in debug mode

Code Snippets

...
server {
 listen       80;
 server_name  example.com;
 ...
 location ~* "^/service/test" {
   root    /var/www/example.com/htdocs;
 }
}
curl -v -L http://example.com/service/test1 | egrep "^> (Host:|GET)"
wget  http://example.com/service/test1 2>&1 | grep Location
$ kubectl get deploy -n <namespace-of-ingress-controller>
NAME                       DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
default-http-backend       1         1         1            1           35m
nginx-ingress-controller   1         1         1            1           35m

$ kubectl edit deploy -n <namespace-of-ingress-controller> nginx-ingress-controller
# Add --v=X to "- args", where X is an integer

Context

StackExchange DevOps Q#11199, answer score: 3

Revisions (0)

No revisions yet.