<p>I need help with setting up TLS termination (using ingress-nginx) for two services in different backends. Basically, the idea is to go with:</p>
<pre><code>https://some.url.here/serviceOne/ -&gt; http://hostOne/
https://some.url.here/serviceTwo/ -&gt; http://hostTwo/someServiceNameHere/
</code></pre>
<p>I tried doing it with <code>rewrite-target: &quot;/&quot;</code>, <code>rewrite-target: &quot;/$1&quot;</code>, and <code>use-regexp: &quot;true&quot;</code>, but connecting to <code>http://hostTwo/someServiceNameHere/</code> constantly fails.</p>
<p>My ingress definition looks like this:</p>
<pre><code>kind: Ingress
metadata:
  name: rp-some-url-here
  namespace: reverse-proxy
  annotations:
    kubernetes.io/ingress.class: nginx
    # ??? nginx.ingress.kubernetes.io/rewrite-target: &quot;/$1&quot;
    # ??? nginx.ingress.kubernetes.io/use-regex: &quot;true&quot;
    nginx.ingress.kubernetes.io/backend-protocol: &quot;HTTP&quot;
    nginx.ingress.kubernetes.io/proxy-ssl-verify: &quot;false&quot;
    nginx.ingress.kubernetes.io/upstream-vhost: &quot;some.url.here&quot;
    nginx.ingress.kubernetes.io/proxy-connect-timeout: &quot;600&quot;
    nginx.ingress.kubernetes.io/proxy-send-timeout: &quot;600&quot;
    nginx.ingress.kubernetes.io/proxy-read-timeout: &quot;600&quot;
    # proxy-buffering is now disabled by default,
    # just having it here for reference
    nginx.ingress.kubernetes.io/proxy-buffering: &quot;off&quot;
spec:
  tls:
  - hosts:
    - some.url.here
    secretName: my-tls-secret
  rules:
  - host: some-url-here
    http:
      paths:
      - backend:
          service:
            name: serviceOne
            port:
              number: 80
        # path: /serviceOne # using this with rewrite-target
        path: /serviceOne/.*
        pathType: Prefix
      - backend:
          service:
            name: serviceTwo
            port:
                number: 8180
        # path: /serviceTwo # using this with rewrite-target
        path: /serviceTwo/.*
        pathType: Prefix
</code></pre>
<p>Service definition is as simply as</p>
<pre><code>---
apiVersion: v1
kind: Service
metadata:
  name: service-one
  namespace: reverse-proxy
spec:
  type: ExternalName
  externalName: some.hostname.here
---
apiVersion: v1
kind: Service
metadata:
  name: service-two
  namespace: reverse-proxy
spec:
  type: ExternalName
  externalName: another.hostname.here
</code></pre>

Robert Heine
<p>here is a quick example of how it should be done ,also make sure that your second service responds to the port that you specified (8180)</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  name: rewrite
  namespace: default
spec:
  ingressClassName: nginx
  rules:
  - host: rewrite.bar.com
    http:
      paths:
      - path: /something(/|$)(.*)
        pathType: Prefix
        backend:
          service:
            name: http-svc1
            port: 
              number: 80
      - path: /something2(/|$)(.*)
        pathType: Prefix
        backend:
          service:
            name: http-svc2
            port: 
              number: 8180

</code></pre>
