服务器上传大文件出现net::ERR_HTTP2_PING_FAILED错误求助
问题
本地环境下向AWS上传任意大小的视频均无报错,但将代码部署至AWS服务器后,上传100MB以上文件时会出现错误(failed)net::ERR_HTTP2_PING_FAILED。已调整PHP.ini文件中所有视频上传及超时限制,但问题仍未解决,求排查方向或遗漏的配置。
相关代码:
return Plupload::file('file', function ($file) { try { $path = Storage::disk('s3')->putFile('medias', $file); $cmd = Storage::disk('s3') ->getDriver() ->getAdapter() ->getClient() ->getCommand('GetObject', [ 'Bucket' => config("filesystems.disks.s3.bucket"), 'Key' => $path, ]); $link = Storage::disk('s3') ->getDriver() ->getAdapter() ->getClient() ->createPresignedRequest($cmd, '+12 hours') ->getUri(); $linkSave=(string) $link; $token = config('services.cloudflare.token'); $accountId = config('services.cloudflare.acountId'); $client = new Client(); //file upload /* $response = $client->request('POST', 'https://api.cloudflare.com/client/v4/accounts/' . $accountId . '/stream', [ 'headers' => [ 'Authorization' => 'Bearer ' . $token, ], 'multipart' => [ [ 'name' => 'file', 'contents' => fopen($file, 'r+'), 'filename' => $file->getClientOriginalName(), ], ] ]);*/ //link upload $response = $client->request('POST', 'https://api.cloudflare.com/client/v4/accounts/' . $accountId . '/stream/copy', [ 'headers' => [ 'Authorization' => 'Bearer ' . $token, 'Content-Type' => 'application/json', ], 'json' => [ "url" => $linkSave, "meta" => [ "name" => $file->getClientOriginalName() ] ] ]); $data = json_decode($response->getBody(), true); // returns an array $path = null; foreach ($data as $key => $dat) { if (is_array($dat) && array_key_exists('preview', $dat)) { $path = $dat['preview']; } } $videoUrl = str_replace('watch', 'iframe', $path); $videoPath = '<iframe src="' . $videoUrl . '" style="border: none; position: absolute; top: 0; left: 0; height: 100%; width: 100%;" allow="accelerometer; gyroscope; autoplay; encrypted-media; picture-in-picture;" allowfullscreen="true" id="stream-player"></iframe>'; $media = Media::create([ 'name' => $file->getClientOriginalName(), 'path' => $videoPath, 'extension' => $file->getClientOriginalExtension(), 'user_id' => auth()->user()->id, ]); return [ 'success' => true, 'message' => 'Upload successful.', ]; } catch (\Exception $exception) { return [ 'success' => false, 'message' => 'Upload error.', ]; } });
排查方向与解决建议
- Web服务器HTTP2超时配置:如果用Nginx,检查
http2_idle_timeout(默认300秒),大文件上传耗时久,建议调至600秒以上;同时调整proxy_connect_timeout、proxy_send_timeout、proxy_read_timeout等代理超时参数。若是Apache,检查Timeout、ProxyTimeout以及HTTP2相关的超时设置。 - AWS负载均衡/网关超时:如果使用了Application Load Balancer(ALB),默认空闲超时为60秒,需在ALB配置中调大至匹配大文件上传的耗时(如300秒以上);若用API Gateway,检查其集成超时和方法超时设置是否足够。
- Guzzle客户端超时设置:代码中使用的
Client是Guzzle,默认超时较短,初始化时需显式设置超时参数:$client = new Client([ 'timeout' => 300, // 请求超时时间,单位秒 'connect_timeout' => 60 // 连接超时时间,单位秒 ]); - Cloudflare Stream拉取环节:预签名链接有效期设置为12小时没问题,但要确保S3桶的权限允许Cloudflare IP访问;另外可以尝试直接分段上传视频到Cloudflare Stream(取消注释代码中被注释的文件上传逻辑),减少先传S3再复制的中间步骤,避免跨服务的超时问题。
- 服务器资源限制:检查AWS服务器的CPU、内存使用率,大文件上传时若资源耗尽可能导致进程被终止;同时查看磁盘IO是否存在瓶颈,影响上传速度进而触发超时。
- 安全组与防火墙规则:AWS安全组是否限制了长时间TCP连接的存活时间;服务器本地防火墙是否有流量阈值或连接超时的限制规则。
内容的提问来源于stack exchange,提问作者mehmet
相关产品推荐
相关产品推荐

