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>
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
--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