Score:1

NGINX / Cloudflare random 520 HTTP errors when HTTP2 is enabled within NGINX

us flag

I'm seeing a problem where Cloudflare returns a 520 HTTP error code to roughly 10% of requests. However the issue does not occur if I bypass the Cloudflare proxy, and request from the server directly.

After lots of troubleshooting, I've discovered if I remove the two http2 parameters after listen, then the issue goes away, and Cloudflare stops returning the 520 errors.

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    ssl_certificate         *path to key*;
    ssl_certificate_key     *path to key*;
    server_name example.com;
    root *path to directory*;
    location / {
        proxy_pass         http://localhost:5000; // proxying asp.net core app
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection keep-alive;
        proxy_set_header   Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
    }
}

Is there a resolution to the problem that allows me to keep the HTTP2 capability?

Score:3
jp flag

The easy explanation is that according to the Understanding Cloudflare HTTP/2 and HTTP/3 Support:

Cloudflare only uses HTTP/1.x between the origin web server and Cloudflare.

You can disable the HTTP/2 on your origin server and still benefit from it between the browser and Cloudflare, as it is enabled by default if you have TLS at Cloudflare's edge network.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.