<p>I have some simple deployments, pods, services and nginx ingress in Kubernetes. I want to use ingress to route to the services (cluster-ip).</p>
<p>However, there are 2 services for 2 pods with the same path (i.e /abc/def). After I applied the ingress.yaml file, I got an error message saying &quot;nginx: [emerg] duplicate location &quot;/abc/def/&quot; in /tmp/nginx/nginx-cfg728288520:2893&quot;.</p>
<p>May I know how to let ingress accepts the same paths with different service and different port?</p>
<p>Here is the ingress.yaml file:</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: &quot;true&quot;
  name: ingress-nginx-default
  namespace: default
spec:
  rules:
  - host: 
    http:
      paths:
      - path: /abc/def/
        pathType: Prefix
        backend:
         service:
           name: service1
           port:
             number: 8090     
      - path: /abc/def
        backend:
          service:
            name: service2
            port:
             number: 8068
        pathType: Prefix
  ingressClassName: nginx
</code></pre>

maantarng
<p>&quot;nginx: [emerg] duplicate location &quot;/abc/def/&quot; in /tmp/nginx/nginx-cfg728288520:2893&quot;. This error indicates the same host with two same paths which is a duplicate location.</p>
<p>You can use  simple fanout based on path or name based virtual hosting.
In order to do this you need to have two hosts that need to be mentioned in the ingress.</p>
<p>based on your example you'd most likely want to have something like <code>foo.bar.com and bar.foo.com</code>. Here's the example from the Kubernetes docs:</p>
<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: name-virtual-host-ingress
spec:
  rules:
    - host: foo.bar.com
      http:
        paths: #path_name
          - backend:
              serviceName: service1
              servicePort: 80
    - host: bar.foo.com
      http:
        paths: #path_name
          - backend:
              serviceName: service2
              servicePort: 80
</code></pre>
