Home > database >  Nginx externalname Azure CDN times out
Nginx externalname Azure CDN times out

Time:09-28

My devs want the following when going to domain.com:

Route nearly all paths to the backend server (I setup an ingress for this)

Route certain paths (i.e. domain.com/site.webmanifest) to the Azure CDN directly

Currently I have 3 files. The working ingress (1), a Service using an ExternalName that points to the CDN (2) and a third ingress for the specific pathing (3).

Sadly I keep getting 504 errors, no matter what I do. I'm also afraid that the ingress rules will fail, as 2 separate ingress files with the same host will merge (and I do not want the rewrite-target on the second).

The following is the result of the NginX log:

[error] 9499#9499: *26224546 [lua] balancer.lua:332: balance(): error while setting current upstream peer IP-ADDRESS invalid port while connecting to upstream, client: K8S-IP-ADDRESS, server: domain.com, request: "GET /site.webmanifests HTTP/2.0", host: "domain.com"

2021/09/23 07:51:39 [error] 9499#9499: *26224546 upstream timed out (110: Operation timed out) while connecting to upstream, client: K8S-IP-ADDRESS, server: domain.com, request: "GET /site.webmanifests HTTP/2.0", upstream: "https://0.0.0.1:80/site.webmanifests", host: "domain.com"

It complains of an invalid port. I have already tried setting up the second ingress with following tags:

nginx.ingress.kubernetes.io/upstream-vhost: cdn.address.com
nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"

And specify portname:

port:
  name: https

But to no avail. I have found this post:

Kubernetes Service Object ExternalName pointing to Azure CDN

Which states what I want to be impossible, but I do not understand the proposed alternative/solution.

Any advice would be appreciated.

Kind regards

CodePudding user response:

Since I only had a limited amount of URL's I had to redirect, I modified the ingress (1) yaml and deleted the service and other ingress.

I added the following annotation:

nginx.ingress.kubernetes.io/server-snippet: |
  location = /robots.txt {
     proxy_pass https://cdn.domain.com/robots.txt;
  }

This seems to work like a charm, I'm open for alternatives though.

  • Related