<p>I'm trying to try to match a host address to a service path, as an example, let's think i have an nginx pod servying to sites: site1 and site2. Let's think about a service called <strong>my-nginx-service</strong> which services my two sites as paths:</p>
<pre><code>- my-nginx-service (178.123.55.37:80) 
    - /site1
    - /site2
</code></pre>
<p>There exists a way to map it to something like:</p>
<pre><code>- host: site-one.mydomain.com
    http:
      paths:
      - backend:
          serviceName: nginx-service
          servicePort: 80
          servicePath: /site2
  - host: site-two.mydomain.com
    http:
      paths:
      - backend:
          serviceName: nginx-service
          servicePort: 80
          servicePath: /site2
</code></pre>
<p>? I have not found anything about it in docs. Or maybe I've not understood well them.</p>
<p>Thank you very much for your time!</p>

Xavis
<p>What you are trying to do (if I understood right) is impossible, because services are unaware of host names. You might be able to reach what you want by modifying nginx configuration within the pod, but that would not be a K8s approach.</p>

<p>What you need to do is to add an ingress resource. Ingresses are aware of host names. They do load balancing between services. So, /site1 one would go to one service, and /site2 to the other one.</p>

<p>This is what the ingress should look like:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress
spec:
  rules:
  - host: site-one.mydomain.com
    http:
      paths:
      - backend:
          serviceName: nginx-service1
          servicePort: 80
  - host: site-two.mydomain.com
    http:
      paths:
      - backend:
          serviceName: nginx-service2
          servicePort: 80
</code></pre>

<p>As you can see site1 and site2 would be running in different deployments, with different services targeting them. Ingress, which is L7 Load Balancer would be able to check the host name and forward the request to the right service, which in the end would hit the right pod.</p>

<p>You can also add paths to each host, so site-one.mydomain.com/path1, site-one.mydomain.com/path2 and site-two.mydomain.com/path1 (for example), would be forwarded to different services.</p>

<p>The Ingress yaml file would look like this:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress
spec:
  rules:
  - host: site-one.mydomain.com
    http:
      paths:
      - path: /path1
        backend:
          serviceName: nginx-service1
          servicePort: 80
      - path: /path2
        backend:
          serviceName: nginx-service2
          servicePort: 8080
      - path: /
        backend:
          serviceName: nginx-service3
          servicePort: 80
  - host: site-two.mydomain.com
    http:
      paths:
      - path: /path1
        backend:
          serviceName: nginx-service1
          servicePort: 80
</code></pre>

<p>I know this is not what you exactly are asking, but this is the right way to achieve what you want. </p>
