Answers: <h1>It just works</h1>
  
  <p>Your configuration is correct.</p>
  
  <p>Provided <code>YAML</code> file generates <code>nginx</code> config like this:</p>
  
  <pre><code>...
  server {
   listen       80;
   server_name  example.com;
   ...
   location ~* "^/service/test" {
     root    /var/www/example.com/htdocs;
   }
  }
  </code></pre>
  
  <p>Testing this config via <a href="https://nginx.viraptor.info/" rel="nofollow noreferrer">this cool tester</a> shows that location filter works:</p>
  
  <ul>
  <li><code>http://example.com/service/test1</code> -> <code>Location: ^/service/test</code></li>
  <li><code>http://example.com/service/test</code> -> <code>Location: ^/service/test</code></li>
  <li><code>http://example.com/login</code> -> <code>Errors: No locations matched</code></li>
  </ul>
  
  <p>For more details, see <a href="https://github.com/kubernetes/ingress-nginx/blob/5f2f0e5db3c3defd34da943002fd6c96835efcbc/docs/user-guide/ingress-path-matching.md" rel="nofollow noreferrer">this explanation of Ingress Path Matching</a> and examples from <a href="https://docs.nginx.com/nginx-ingress-controller/configuration/configuration-examples/" rel="nofollow noreferrer">NGINX Docs</a>:</p>
  
  <blockquote>
    <ul>
    <li><a href="https://github.com/nginxinc/kubernetes-ingress/tree/v1.6.3/examples" rel="nofollow noreferrer"><em>Examples</em></a> show how to use advanced NGINX features in Ingress resources with annotations.</li>
    <li><a href="https://github.com/nginxinc/kubernetes-ingress/tree/v1.6.3/examples-of-custom-resources" rel="nofollow noreferrer"><em>Examples of Custom Resources</em></a> show how to use VirtualServer and VirtualServerResources for a few use cases.</li>
    </ul>
  </blockquote>
  
  <h1>Check your app</h1>
  
  <p>Check your app, maybe it forward non-authorized requests to <code>/login</code> url.
  You may use <code>curl -v</code> or <code>wget</code>, e.g:</p>
  
  <pre><code>curl -v -L http://example.com/service/test1 | egrep "^&gt; (Host:|GET)"
  </code></pre>
  
  <pre><code>wget  http://example.com/service/test1 2&gt;&amp;1 | grep Location
  </code></pre>
  
  <h1>Howto debug <code>nginx ingress</code></h1>
  
  <p>There is an <a href="http://nginx.org/en/docs/debugging_log.html" rel="nofollow noreferrer"><code>Nginx</code> debug mode</a> for debugging <code>nginx</code> <code>locations</code> and redirects.
  To enable it, use <code>--v=5</code> in <code>kubectl edit deploy</code>.</p>
  
  <p>See: <a href="https://kubernetes.github.io/ingress-nginx/troubleshooting/#debug-logging" rel="nofollow noreferrer">k8s debug logging</a>:</p>
  
  <blockquote>
    <p>Using the flag <code>--v=XX</code> it is possible to increase the level of logging. This is performed by editing the deployment.</p>
  
  <pre><code>$ kubectl get deploy -n &lt;namespace-of-ingress-controller&gt;
  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 &lt;namespace-of-ingress-controller&gt; nginx-ingress-controller
  # Add --v=X to "- args", where X is an integer
  </code></pre>
    
    <blockquote>
      <ul>
      <li><code>--v=2</code> shows details using <code>diff</code> about the changes in the configuration in nginx</li>
      <li><code>--v=3</code> shows details about the service, Ingress rule, endpoint changes and it dumps the nginx configuration in JSON format</li>
      <li><code>--v=5</code> configures NGINX in <a href="http://nginx.org/en/docs/debugging_log.html" rel="nofollow noreferrer">debug mode</a></li>
      </ul>
    </blockquote>
  </blockquote>
  
Answers: CC BY-SA 4.0
Answers: 2020-04-04T05:08:45.567Z
Answers: The /login page was coming from the container, it was not the nginx redirects. Thanks, debug mode helped in unfold the ingress
Answers: Pradeep Upadhyay
Answers: CC BY-SA 4.0
Answers: 2020-04-04T06:06:09.393Z
Answers: 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.'
Answers: Yasen
Answers: CC BY-SA 4.0
Answers: 2020-04-01T14:35:34.233Z
Answers: 2020-04-03T19:34:35.227Z
Answers: 2020-04-03T19:34:35.227Z
Answers: Yasen
Body: <p>I am trying to access a url example.com/service/test1 but it redircts me to example.com/login.</p>
  
  <p>Below is my YAMl file:</p>
  
  <pre><code>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
  </code></pre>
  
Tags: <nginx><ingress><azure-kubernetes-service>
Title: Nginx ingress controller redirects the url to /login
UserDisplayName: Pradeep Upadhyay
ThreadText: # Nginx ingress controller redirects the url to /login
  
  (Asked by: username_0 on 2020-03-31)
  
  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
  
  ```
  
  **Tags:** nginx, ingress, azure-kubernetes-service
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-04-01. Score: 3
  
  # 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](https://nginx.viraptor.info/) 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](https://github.com/kubernetes/ingress-nginx/blob/5f2f0e5db3c3defd34da943002fd6c96835efcbc/docs/user-guide/ingress-path-matching.md) and examples from [NGINX Docs](https://docs.nginx.com/nginx-ingress-controller/configuration/configuration-examples/):
  
  > * [*Examples*](https://github.com/nginxinc/kubernetes-ingress/tree/v1.6.3/examples) show how to use advanced NGINX features in Ingress resources with annotations.
  > * [*Examples of Custom Resources*](https://github.com/nginxinc/kubernetes-ingress/tree/v1.6.3/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](http://nginx.org/en/docs/debugging_log.html) for debugging `nginx` `locations` and redirects.
  To enable it, use `--v=5` in `kubectl edit deploy`.
  
  See: [k8s debug logging](https://kubernetes.github.io/ingress-nginx/troubleshooting/#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](http://nginx.org/en/docs/debugging_log.html)
  
  > **Comments:**
  > **username_0**: The /login page was coming from the container, it was not the nginx redirects. Thanks, debug mode helped in unfold the ingress  
  > **username_1**: Hi @username_0. 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.'  
  
  ---
  
  