<p><strong>Problem</strong></p>

<p>I would like to host multiple services on a single domain name under different paths. The problem is that I'm unable to get request path rewriting working using <code>nginx-ingress</code>.</p>

<p><strong>What I've tried</strong></p>

<p>I've installed nginx-ingress using <a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-an-nginx-ingress-on-digitalocean-kubernetes-using-helm" rel="nofollow noreferrer">these instructions</a>:</p>

<pre class="lang-sh prettyprint-override"><code>helm install stable/nginx-ingress --name nginx-ingress --set controller.publishService.enabled=true
</code></pre>

<pre><code>CHART                   APP VERSION
nginx-ingress-0.3.7     1.5.7
</code></pre>

<p>The example works great with hostname based backends:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: hello-kubernetes-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
  - host: first.testdomain.com
    http:
      paths:
      - backend:
          serviceName: hello-kubernetes-first
          servicePort: 80
</code></pre>

<p>However, I can't get path rewriting to work. This version redirects requests to the <code>hello-kubernetes-first</code> service, but doesn't do the path rewrite so I get a 404 error from that service because it's looking for the /foo directory within that service (which doesn't exist).</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: hello-kubernetes-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: first.testdomain.com
    http:
      paths:
      - backend:
          serviceName: hello-kubernetes-first
          servicePort: 80
        path: /foo
</code></pre>

<p>I've also tried <a href="https://kubernetes.github.io/ingress-nginx/examples/rewrite/" rel="nofollow noreferrer">this example</a> for paths / rewriting:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: hello-kubernetes-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  rules:
  - host: first.testdomain.com
    http:
      paths:
      - backend:
          serviceName: hello-kubernetes-first
          servicePort: 80
        path: /foo(/|$)(.*)
</code></pre>

<p>But the requests aren't even directed to the <code>hello-kubernetes-first</code> service.</p>

<p>It appears that my rewrite configuration isn't making it to the <code>/etc/nginx/nginx.conf</code> file. When I run the following, I get no results:</p>

<pre class="lang-sh prettyprint-override"><code>kubectl exec nginx-ingress-nginx-ingress-XXXXXXXXX-XXXXX  cat /etc/nginx/nginx.conf | grep rewrite
</code></pre>

<p>How do I get the path rewriting to work?</p>

<p><strong>Additional information:</strong></p>

<ul>
<li>kubectl / kubernetes version: <code>v1.14.8</code></li>
<li>Hosting on Azure Kubernetes Service (AKS)</li>
</ul>

RQDQ
<p>This is not likely to be an issue with AKS, as the components you use are working on top of Kubernetes layer. However, if you want to be sure you can deploy this on top of minikube locally and see if the problem persists. </p>

<p>There are also few other things to consider:</p>

<ol>
<li>There is a <a href="https://learn.microsoft.com/en-us/azure/aks/ingress-tls" rel="nofollow noreferrer">detailed guide</a> about creating ingress controller on AKS. The guide is up to date and confirmed to be working fine. </li>
</ol>

<blockquote>
  <p>This article shows you how to deploy the NGINX ingress controller in
  an Azure Kubernetes Service (AKS) cluster. The cert-manager project is
  used to automatically generate and configure Let's Encrypt
  certificates. Finally, two applications are run in the AKS cluster,
  each of which is accessible over a single IP address.</p>
</blockquote>

<ol start="2">
<li>You may also want to use alternative like <a href="https://github.com/helm/charts/tree/master/stable/traefik" rel="nofollow noreferrer">Traefik</a>:</li>
</ol>

<blockquote>
  <p>Traefik is a modern HTTP reverse proxy and load balancer made to
  deploy microservices with ease.</p>
</blockquote>

<ol start="3">
<li>Remember that:</li>
</ol>

<blockquote>
  <p>Operators will typically wish to install this component into the
  <code>kube-system</code> namespace where that namespace's default service account
  will ensure adequate privileges to watch Ingress resources
  cluster-wide.</p>
</blockquote>

<p>Please let me know if that helped. </p>
