宝塔配置NGINX反向代理,webman文件下载超过4M就提示net::ERR_HTTP2_PROTOCOL_ERROR

在NGINX反向代理那里加上

proxy_set_header Connection 'Keep-Alive';

完整NGINX

#PROXY-START/

location /
{
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    proxy_set_header Upgrade $http_upgrade;
    # 【核心解法】明确传递 Keep-Alive,确保 Workerman 底层 Socket 大文件传输时不被重置
    proxy_set_header Connection 'Keep-Alive';

    proxy_http_version 1.1;
    # proxy_hide_header Upgrade;

    proxy_max_temp_file_size 0;
    proxy_ignore_client_abort on;

    add_header X-Cache $upstream_cache_status;
    #Set Nginx Cache

    set $static_filebdPEJ7fN 0;
    if ( $uri ~* "\.(gif|png|jpg|css|js|woff|woff2)$" )
    {
        set $static_filebdPEJ7fN 1;
        expires 10m;
    }
    if ( $static_filebdPEJ7fN = 0 )
    {
        add_header Cache-Control no-cache;
    }
}
#PROXY-END/

 

当时问题是

 

NGINX日志报错

2026/09/01 15:26:18 [error] 340820#0: *142508 upstream prematurely closed connection while sending to client, client: xxx.xxx.xxx.xxx, server:

浏览器报错

Failed to load resource: net::ERR_HTTP2_PROTOCOL_ERROR

webman代码

$response = new \support\Response();
return  $response->file('文件地址');

 

额,问题出在宝塔无法配置upstream,不然按照webman官方的配置,应该是不会出现这个问题的

下面的是官方的配置,重点应该是 keepalive 10240;     proxy_set_header Connection "";  有点乱,我也没弄明白怎么回事

upstream webman {
    server 127.0.0.1:8787;
    keepalive 10240;
}

server {
  server_name 站点域名;
  listen 80;
  access_log off;
  # 注意,这里一定是webman下的public目录,不能是webman根目录
  root /your/webman/public;

  location / {
    try_files $uri @proxy;
  }

  location @proxy {
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
    proxy_pass http://webman;
  }

  # 拒绝访问所有以 .php 结尾的文件
  location ~ \.php$ {
      return 404;
  }

  # 允许访问 .well-known 目录
  location ~ ^/\.well-known/ {
    allow all;
  }

  # 拒绝访问所有以 . 开头的文件或目录
  location ~ /\. {
      return 404;
  }

}

 

image

 

posted @ 2026-09-02 09:45  忙于厮杀  阅读(7)  评论(0)    收藏  举报