大网数据广告活动
服务器运维问答

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

· 52CE 我爱测

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 troubleshootin…

问题原文

原帖链接 · TidyDev · CC BY-SA 4.0

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?

已采纳解答

原帖链接 · Esa Jokinen · CC BY-SA 4.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2021-07-18)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。