<p>I deployed an Angular SPA application in Azure Kubernetes. I was trying to access the application through the Ingress Nginx controller. The Ingress is pointing to xxx.xxx.com and the app is deployed in the path "/". So when I accessed the application the application is loading fine. But when I try to navigate to any other page other than index.html by entering it directly in the browser (ex: eee.com/homepage), I get 404 Not Found.</p>

<p>Following is the dockerfile content</p>

<pre><code># base image
FROM nginx:1.16.0-alpine
# copy artifact build from the 'build environment'
COPY ./app/ /usr/share/nginx/html/
RUN rm -f /etc/nginx/conf.d/nginx.config
COPY ./nginx.config /etc/nginx/conf.d/nginx.config
# expose port 80
EXPOSE 80
# run nginx
CMD ["nginx", "-g", "daemon off;"]
</code></pre>

<p>Ingress.yaml</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: app-frontend-ingress
  namespace: app
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: "true"
    nginx.ingress.kubernetes.io/add-base-url: "true"
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  tls:
  - hosts:
    - xxx.com
    secretName: tls-dev-app-ingress
  rules:
  - host: xxx.com
    http:
      paths:
      - backend:
          serviceName: poc-service
          servicePort: 80
        path: /
</code></pre>

<p>nginx.conf</p>

<pre><code>server {

  listen 80;

  location / {
    root   /usr/share/nginx/html;
    index  index.html index.htm;
    try_files $uri $uri/ /index.html;
  }

  error_page   500 502 503 504  /50x.html;

  location = /50x.html {
    root   /usr/share/nginx/html;
  }

}
</code></pre>

<p>You can add a configuration-snippet that will take care of rewriting any path to <code>/</code>:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: app-frontend-ingress
  namespace: app
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: "true"    
    nginx.ingress.kubernetes.io/configuration-snippet: |
      rewrite /([^.]+)$ / break;
      [...]
</code></pre>

<p>For example, if you go to <code>host.com/xyz</code> it will be redirected to <code>host.com</code></p>
