<p>I search (since many days ...) How to use Ingress Nginx in order to use External url as backend.</p>
<p>Yes I use Service object with externalName. I also test many many directive in nginx without succes...</p>
<p>The goal is simple:</p>
<ul>
<li>user can resolv and join only my public URL (url-public.com &amp; url-public-2.com)</li>
<li>I want to send request to external backend than is out of my control and cluster (url-ext.com)</li>
</ul>
<p>My ingress can resolv url-ext.com, user cannot. Of course, url-ext.com have here proper certificat and is expose as HTTPS ;).
Nota : My ingress expose 2 url, but I don't think this is important.</p>
<p>My Code :</p>
<p>Service :</p>
<pre class="lang-yaml prettyprint-override"><code>kind: Service
apiVersion: v1
metadata:
  name: external-eip
  namespace: external-url
spec:
  type: ExternalName
  externalName: url-ext.com
</code></pre>
<p>Ingress :</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: external-eip
  namespace: external-url
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/backend-protocol: &quot;HTTPS&quot;
    nginx.ingress.kubernetes.io/upstream-vhost: &quot;url-ext.com&quot;
    nginx.ingress.kubernetes.io/configuration-snippet: |
      #      more_clear_input_headers &quot;Host&quot; &quot;X-Forwarded-Host&quot;;
      more_set_input_headers 'Host: url-ext.com';
      proxy_set_header Host url-ext.com;

spec:
  rules:
  - host: url-public.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: external-eip
            port:
              number: 443
  - host: url-public-2.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: external-eip
            port:
              number: 443
</code></pre>
<p>Result (curl or Browser access ) :</p>
<pre><code>&lt;html&gt;
&lt;head&gt;&lt;title&gt;504 Gateway Time-out&lt;/title&gt;&lt;/head&gt;
&lt;body&gt;
&lt;center&gt;&lt;h1&gt;504 Gateway Time-out&lt;/h1&gt;&lt;/center&gt;
&lt;hr&gt;&lt;center&gt;nginx&lt;/center&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p>And Ingress Log :</p>
<pre><code>2021/08/06 21:44:45 [error] 10873#10873: *2914631 upstream timed out (110: Operation timed out) while connecting to upstream, client: 10.203.65.14, server: url-public.com, request: &quot;GET / HTTP/2.0&quot;, upstream: &quot;https://10.203.64.5:443/&quot;, host: &quot;url-ext.com&quot;
</code></pre>
<p>10.203.64.5 is the real IP of url-ext.com.</p>
<p>And, <code>curl https://10.203.64.5:443/ -k -v -H &quot;Host: url-ext.com&quot;</code> work.</p>
<p>Don't ask me &quot;why using this annotation&quot;, I don't know :p many Google search and many test ...</p>
<p>So, what is the correct ingress configuration for using externalName, when this externalName is (probably) under RP also ?</p>
<p>Nota : Rewrite and other redirect not work, because it rewrite user location and I don't want it. User canno't acces and resolv url-ext.com, only url-public.com.</p>
<p>Br, Thanks</p>

TIPA Sylvaire-Kevin
<p>Reply to my self. The problem was my Ingress (and all my K8S cluster) is under HTTP Squid proxy.</p>
<p>I have mounted all env variable for proxy but it seems the Ingress container doesn't use it ...</p>
<p>So, to get it working, I allow my cluster to outbound 80/443 ports to the destination.</p>
<p>You just need this annotation:</p>
<pre class="lang-yaml prettyprint-override"><code>    nginx.ingress.kubernetes.io/backend-protocol: &quot;HTTPS&quot;
    nginx.ingress.kubernetes.io/upstream-vhost: &quot;url-ext.com&quot;
</code></pre>
<p>But, if any of you know how to setup my Ingress to use my HTTP proxy, I will need it.</p>
<p>br</p>
