首页 > 解决方案 > nginx 镜像模块对大型响应主体的“对等连接重置”

问题描述

我想使用ngx_http_mirror_module将请求复制到另一个后端。
这是我的 nginx.conf。
Nginx 版本是 1.19.10

worker_processes  1;

error_log  logs/error.log  info;

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  logs/access.log  main;

    sendfile        on;

    keepalive_timeout  65;

    server {
        listen       8888;
        server_name  localhost;

        location / {
            proxy_pass http://127.0.0.1:8080;
            mirror /mirror;
        }

        location /mirror {
            internal;
            proxy_pass http://127.0.0.1:18080$request_uri;
        }
    }
}

我的 Spring 应用程序监听 8080 和 18080。

问题是当处理镜像请求的后端服务器返回一个大的主体响应时,后端服务器会抛出 ClientAbortException,因为connection reset by peer. nginx 错误日志中没有记录任何内容。nginx 访问日志记录镜像请求的状态 200。

当响应大小为 4k 字节或更大时,往往会出现问题。增加proxy_buffer_size可能会解决问题,但是如果响应大小很大(8k字节或更大?),即使它小于proxy_buffer_size,也会出现问题。

我尝试更改 subrequest_output_buffer_size,但没有任何改变。

我怎样才能停止错误?

标签: nginxnginx-module

解决方案


推荐阅读