Proxy traffic through cloudflare CDN to my HTTPs server fails with 521

That’s your problem. Switch to Full (strict) (or temporarily Full if your origin certificate has issues).

On Flexible the connection from Cloudflare to your origin is over HTTP. Full and Full (strict) use HTTPS between Cloudflare and the origin.

You can see your origin returns 502 to HTTP connections, but 200 to HTTPS. Cloudflare’s proxy is seeing your 502 (as it’s connecting over HTTP) and returning an error to the client.

curl -I http://test2.eden-test1.com
HTTP/1.1 502 Bad Gateway
Cache-Control: private, max-age=0, no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Referrer-Policy: same-origin
Expires: Thu, 01 Jan 1970 00:00:01 GMT
Proxy-Status: Cloudflare-Proxy;error=connection_refused
Cf-Team: 1c7932316d000065361b1b1400000001
Content-Length: 10160
Date: Thu, 16 Nov 2023 10:06:56 GMT

curl -I --insecure https://test2.eden-test1.com
HTTP/1.0 200 OK
Server: SimpleHTTP/0.6 Python/3.9.16
Date: Thu, 16 Nov 2023 10:08:17 GMT
Content-type: text/html; charset=utf-8
Content-Length: 870

curl -I --insecure https://test2.eden-test1.com:8443
HTTP/1.0 200 OK
Server: SimpleHTTP/0.6 Python/3.9.16
Date: Thu, 16 Nov 2023 10:08:28 GMT
Content-type: text/html; charset=utf-8
Content-Length: 870