'connection reset by peer' for large response body by nginx mirror module

605 views Asked by At

I want to copy requests to another backend with ngx_http_mirror_module.
This is my nginx.conf.
Nginx version is 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;
        }
    }
}

My Spring applications listen on 8080 and 18080.

The problem is that when the backend server which handles the mirrored request returns a large body response, the backend server throws ClientAbortException because of connection reset by peer. Nothing is recorded in the nginx error log. The nginx access log records status 200 for the mirrored request.

Problems tend to occur when the response size is 4k bytes or larger. Increasing proxy_buffer_size may solve the problem, but if the response size is large (8k bytes or more?), Even if it is smaller than proxy_buffer_size, problems will occur.

I tried to change subrequest_output_buffer_size, but nothing changed.

How can I stop the error?

0

There are 0 answers