title: Kubernetes Ingress: nginx, use-regex to match exact URL path
body: <p>I have a few pods that I am trying to match URLs for their respective services.</p>
  <p>Please note that I <strong>need to use</strong> <code>nginx.ingress.kubernetes.io/rewrite-target</code> to solve this and <strong>not</strong> <code>nginx.ingress.kubernetes.io/rewrite-target</code></p>
  <p>My ingress config file looks like this. Notice the <code>/api/tile-server/</code> does not have any regex pattern</p>
  <pre><code>apiVersion: networking.k8s.io/v1beta1
  kind: Ingress
  metadata:
    name: ingress-service
    annotations:
      nginx.ingress.kubernetes.io/ssl-redirect: &quot;true&quot;
      nginx.ingress.kubernetes.io/force-ssl-redirect: &quot;true&quot;
      nginx.ingress.kubernetes.io/use-regex: &quot;true&quot;
      kubernetes.io/ingress.class: &quot;nginx&quot;
      cert-manager.io/cluster-issuer: &quot;letsencrypt-prod&quot;
    namespace: default
  spec:
    tls:
      - hosts:
          - example.com
        secretName: tls-secret
    rules:
      - host: example.com
        http:
          paths:
            - path: /?(.*)
              backend:
                serviceName: client
                servicePort: 80
            - path: /api/auth/?(.*)
              backend:
                serviceName: auth
                servicePort: 8000
            - path: /api/data/?(.*)
              backend:
                serviceName: data
                servicePort: 8001
            - path: /api/tile-server/
              backend:
                serviceName: tile-server
                servicePort: 7800
  </code></pre>
  <ul>
  <li><code>client</code> pod is a react app built inside nginx docker image working fine</li>
  <li><code>nginx.conf</code> looks like this (if it's helpful)</li>
  </ul>
  <pre><code>server {
      # listen on port 80
      listen 80;
      # where the root here
      root /usr/share/nginx/html;
      # what file to server as index
      index index.html index.htm;
  
      location / {
          # First attempt to serve request as file, then
          # as directory, then fall back to redirecting to index.html
          try_files $uri $uri/ /index.html;
      }
  
      # Media: images, icons, video, audio, HTC
      location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
          expires 1M;
          access_log off;
          add_header Cache-Control &quot;public&quot;;
      }
  
      # Javascript and CSS files
      location ~* \.(?:css|js)$ {
          try_files $uri =404;
          expires 1y;
          access_log off;
          add_header Cache-Control &quot;public&quot;;
      }
  
      # Any route containing a file extension (e.g. /devicesfile.js)
      location ~ ^.+\..+$ {
          try_files $uri =404;
      }
  }
  </code></pre>
  <ul>
  <li><code>auth</code> and <code>data</code> are Flask API pods working fine</li>
  <li><code>tile-server</code> is also a Flask pod but need not do any pattern matching. I need to match the exact <code>/api/tile-server/</code> URL</li>
  </ul>
  <p>I have tried the following patterns but failed:</p>
  <ul>
  <li><code>/api/tile-server/</code></li>
  <li><code>/api/tile-server/?(.*)</code></li>
  <li><code>/api/tile-server(/|$)?(.*)</code></li>
  </ul>
  <p>I can confirm that the pods/services are running on their proper ports and I am able to access them through node ports but not through load balancer/domain.
  What would be the right pattern to exactly match <code>/api/tile-server/</code> URL?</p>