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
  name: test-ing
  namespace: test
     nginx.ingress.kubernetes.io/ssl-redirect: "false"
     nginx-ingress.kubernetes.io/use-regex: true

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

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 <namespace-of-ingress-controller>
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
  • --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
  • The /login page was coming from the container, it was not the nginx redirects. Thanks, debug mode helped in unfold the ingress – Pradeep Upadhyay Apr 4 '20 at 5:08
  • Hi @pradeep-upadhyay. Glad that my answer helped you. Correct, nginx redirects work as I described. And redirects to /login was due to application. As I wrote: 'Your configuration is correct.' – Yasen Apr 4 '20 at 6:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.