打开gzip会切断来自上游的响应

  • 本文关键字:响应 gzip 打开 nginx
  • 更新时间 :
  • 英文 :


我的上游服务器返回极大的JSON响应(5~8GB)。
我试图通过在nginx上启用gzip来压缩这些响应。这是我的配置

server {
listen 0.0.0.0:8080;

location / {
gzip on;
gzip_comp_level 1;
gzip_types *;
gzip_proxied any;
proxy_pass http://localhost:8081;
}
}

这个配置在技术上是有效的。至少,它适用于较小的响应(压缩前约150MB)。当我尝试下载大响应(压缩前约7.5GB)

curl -v --compressed --output /path_to_file -X POST http://localhost:8080 --data '{data}'

它在中间被截断了,也就是说,我从curl

中看到这个消息
curl: (18) transfer closed with outstanding read data remaining

和响应本身是不完整的(平均它只下载了~7.5GB中的~5.3GB)

我也看到了nginx的日志

2022/04/20 01:18:45 [error] 37#37: *135 upstream prematurely closed connection while reading upstream, client: 127.0.0.1, server: , request: "POST / HTTP/1.1", upstream: "http://127.0.0.1:8081/", host: "localhost:8080"

我尝试增加proxy_max_temp_file_size,并且,我尝试禁用缓冲。没有什么作品

任何想法?

编辑:这是nginx.conf是内置在docker图像我使用

worker_processes  auto;
error_log         "/opt/bitnami/nginx/logs/error.log";
pid               "/opt/bitnami/nginx/tmp/nginx.pid";
events {
worker_connections  1024;
}
http {
include       mime.types;
default_type  application/octet-stream;
log_format    main '$remote_addr - $remote_user [$time_local] '
'"$request" $status  $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log    "/opt/bitnami/nginx/logs/access.log" main;
add_header    X-Frame-Options SAMEORIGIN;
client_body_temp_path  "/opt/bitnami/nginx/tmp/client_body" 1 2;
proxy_temp_path        "/opt/bitnami/nginx/tmp/proxy" 1 2;
fastcgi_temp_path      "/opt/bitnami/nginx/tmp/fastcgi" 1 2;
scgi_temp_path         "/opt/bitnami/nginx/tmp/scgi" 1 2;
uwsgi_temp_path        "/opt/bitnami/nginx/tmp/uwsgi" 1 2;
sendfile           on;
tcp_nopush         on;
tcp_nodelay        off;
gzip               on;
gzip_http_version  1.0;
gzip_comp_level    2;
gzip_proxied       any;
gzip_types         text/plain text/css application/javascript text/xml application/xml+rss;
keepalive_timeout  65;
ssl_protocols      TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers        HIGH:!aNULL:!MD5;
client_max_body_size 80M;
server_tokens off;
absolute_redirect  off;
port_in_redirect   off;
include  "/opt/bitnami/nginx/conf/server_blocks/*.conf";
# HTTP Server
server {
# Port to listen on, can also be set in IP:PORT format
listen  8080;
include  "/opt/bitnami/nginx/conf/bitnami/*.conf";
location /status {
stub_status on;
access_log   off;
allow 127.0.0.1;
deny all;
}
}
}

在类似的情况下,location块中的这一行解决了问题

proxy_http_version 1.1;

似乎gzip 'Ed响应与http2不兼容

最新更新