Answers: <p>I had the same issue when trying Microsofts tutorial. Adding <code>host</code> under the <code>rules</code> section worked for me.</p>
  <p><strong>Example:</strong></p>
  <pre><code>spec:
    ingressClassName: nginx
    rules:
    - host: {your_app}.northeurope.cloudapp.azure.com
      http:
        paths:
        - path: /test(/|$)(.*)
          pathType: Prefix
          backend:
            service:
              name: mockserver-service
              port:
                number: 1234
            
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2022-09-30T13:46:39.693Z
Answers: 2022-09-30T13:50:32.043Z
Answers: 2022-09-30T13:50:32.043Z
Answers: Easwar AB
Body: <p>I want to have an API service that I want to reach under <code>/api</code>, and other requests to fall back to a frontend service.</p>
  <p>Peculiar is that this worked locally with minikube, but now that I deployed on Azure Kubernetes Service (I used <a href="https://learn.microsoft.com/en-us/azure/aks/ingress-basic" rel="nofollow noreferrer">this official MS tutorial</a> to add an ingress controller), I can not get it to work.</p>
  <pre><code>apiVersion: networking.k8s.io/v1
  kind: Ingress
  metadata:
    name: my-ingress
    annotations:
      nginx.ingress.kubernetes.io/rewrite-target: /$1
  spec:
    rules:
    - http:
        paths:
        - path: /api/(.*)
          pathType: Prefix
          backend:
            service:
              name: api-service
              port:
                number: 9002
        - path: /(.*)
          pathType: Prefix
          backend:
            service:
              name: frontend-service
              port:
                number: 9001
  </code></pre>
  <p>That worked just fine on minikube, but on AKS, this causes <strong>a timeout</strong> when I try to open the publicly available IP. I have tried the following things:</p>
  <ul>
  <li>Change the frontend path to <code>(/|$)(.*)</code><br />
  Together with changing the rewrite-target to <code>/$2</code>. <code>kubectl</code> <strong>will not even deploy</strong> this because the path needs to be absolute.</li>
  <li>Change the frontend path to <code>/</code><br />
  Now <strong>everything returns the frontend index.html</strong>, even if the request is for <code>/style.css</code> or <code>favicon.ico</code> etc. (unless it starts with <code>/api</code>).</li>
  <li>Change the frontend path to <code>/</code> and remove the rewrite-target<br />
  Then the frontend works fine, but <strong>the api service doesn't &quot;fit&quot;</strong> as intended. The api service has a call <code>/get-employee</code>, which I want to call under <code>/api/get-employee</code>, but I can't do that unless the api service itself would already have it under <code>/api/get-employee</code>.</li>
  </ul>
  <p>How can I add a &quot;root&quot; or &quot;fallback&quot; service while still using rewrite-target?</p>
  
Tags: <kubernetes><ingress><azure-kubernetes-service><ingress-nginx>
Title: How can I use rewrite-target on the root path with Azure Kubernetes Service?
UserDisplayName: Raphael Schmitz
ThreadText: # How can I use rewrite-target on the root path with Azure Kubernetes Service?
  
  (Asked by: username_0 on 2022-09-23)
  
  I want to have an API service that I want to reach under `/api`, and other requests to fall back to a frontend service.
  
  Peculiar is that this worked locally with minikube, but now that I deployed on Azure Kubernetes Service (I used [this official MS tutorial](https://learn.microsoft.com/en-us/azure/aks/ingress-basic) to add an ingress controller), I can not get it to work.
  
  ```
  apiVersion: networking.k8s.io/v1
  kind: Ingress
  metadata:
    name: my-ingress
    annotations:
      nginx.ingress.kubernetes.io/rewrite-target: /$1
  spec:
    rules:
    - http:
        paths:
        - path: /api/(.*)
          pathType: Prefix
          backend:
            service:
              name: api-service
              port:
                number: 9002
        - path: /(.*)
          pathType: Prefix
          backend:
            service:
              name: frontend-service
              port:
                number: 9001
  
  ```
  
  That worked just fine on minikube, but on AKS, this causes **a timeout** when I try to open the publicly available IP. I have tried the following things:
  
  * Change the frontend path to `(/|$)(.*)`  
    Together with changing the rewrite-target to `/$2`. `kubectl` **will not even deploy** this because the path needs to be absolute.
  * Change the frontend path to `/`  
    Now **everything returns the frontend index.html**, even if the request is for `/style.css` or `favicon.ico` etc. (unless it starts with `/api`).
  * Change the frontend path to `/` and remove the rewrite-target  
    Then the frontend works fine, but **the api service doesn't "fit"** as intended. The api service has a call `/get-employee`, which I want to call under `/api/get-employee`, but I can't do that unless the api service itself would already have it under `/api/get-employee`.
  
  How can I add a "root" or "fallback" service while still using rewrite-target?
  
  **Tags:** kubernetes, ingress, azure-kubernetes-service, ingress-nginx
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-09-30. Score: 1
  
  I had the same issue when trying Microsofts tutorial. Adding `host` under the `rules` section worked for me.
  
  **Example:**
  
  ```
  spec:
    ingressClassName: nginx
    rules:
    - host: {your_app}.northeurope.cloudapp.azure.com
      http:
        paths:
        - path: /test(/|$)(.*)
          pathType: Prefix
          backend:
            service:
              name: mockserver-service
              port:
                number: 1234
            
  
  ```
  
  
  ---
  
  