title: Route by path in front web applications using nginx or kukbernetes ingress
body: <p>Suppose I own a domain name xxx.yyy.com, but I doesn't own any subdomain name (*.xxx.yyy.com) of it.</p>
  <p>So I have to route each HTTP request to its corresponding service by <code>path</code>. For example, routing xxx.yyy.com/app1/ to service <code>app1</code> and xxx.yyy.com/app2/ to service <code>app2</code>.</p>
  <p>I config my kubernestes resources as below:</p>
  <pre class="lang-yaml prettyprint-override"><code>apiVersion: networking.k8s.io/v1
  kind: Ingress
  metadata:
    name: ingress
    annotations:
      nginx.ingress.kubernetes.io/rewrite-target: /
      kubernetes.io/ingress.class: &quot;nginx&quot;
  spec:
    rules:
      - host: xxx.yyy.com
        http:
          paths:
            - pathType: Prefix
              path: &quot;/app1&quot;
              backend:
                service:
                  name: app1
                  port:
                    number: 8000
            - pathType: Prefix
              path: &quot;/app2&quot;
              backend:
                service:
                  name: app2
                  port:
                    number: 8000
  ---
  
  apiVersion: v1
  kind: Service
  metadata:
    name: app1
  spec:
    selector:
      app: app1
    ports:
      - protocol: TCP
        port: 8000
  
  ---
  
  apiVersion: v1
  kind: Service
  metadata:
    name: app2
  spec:
    selector:
      app: app2
    ports:
      - protocol: TCP
        port: 8000
  
  </code></pre>
  <p>This works in most of the cases, except in front webapps.</p>
  <p>In a front webapp's HTML and javascript code, we refer its assets (images, HTTP APIs) on the backend server by root path (&quot;/&quot;) , as if it is deployed on its own server.</p>
  <p>For example in the javascript code of <code>app1</code> , we call <code>fetch('/api/getUsers')</code> instead of <code>fetch('/app1/api/getUsers')</code>, so the ingress failed to route <code>/api/getUsers</code> to service <code>app1</code>.</p>
  <p>I know it can be solved easily by routing request by <code>host</code> not by <code>path</code>. But I don't have the permission to create subdomains.</p>
  <p>So how can this scenario of front webapps be solved by routing by <code>path</code> ingress?</p>