# Why 'client closed prematurely connection while sending request to upstream'?

**URL:** <https://www.ruby-forum.com/t/why-client-closed-prematurely-connection-while-sending-request-to-upstream/166024>\
**Category:** NGINX\
**Created:** [April 21, 2009, 5:02am UTC](https://www.ruby-forum.com/t/why-client-closed-prematurely-connection-while-sending-request-to-upstream/166024 "2009-04-21T05:02:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yu.Cheung](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/ce73a5/32.png) [@Yu.Cheung](https://www.ruby-forum.com/u/Yu.Cheung)\
**Post date:** [April 21, 2009, 5:02am UTC](https://www.ruby-forum.com/t/why-client-closed-prematurely-connection-while-sending-request-to-upstream/166024/1 "2009-04-21T05:02:36Z")

</div>

Hi,  
All.  
I want to proxy twice. but there was something wrong with it.

what I want to do:

```
client send request----->nginx server------->sending(proxy_pass)

```

its header to the backend server 1 ----\>back to ngx server----\>proxy  
pass to the second backend server----\>back to ngx server----\>response  
to client.

```
but when the request was sent to backend server 1, 'the client

```

closed prematurely connection while sending request to upstream’ came,  
all of my http servsers are Nginx.

the simple conf (just use virtual 3 servers) is:

http {  
include mime.types;  
default\_type text/html;  
expires -1;

sendfile on;

client\_max\_body\_size 10000m;

server {

```
server_name front;
listen 8389;

location / {

if ($uri ~ "/(.*)") {
  set $fn $1;
  }

proxy_ignore_client_abort on;

proxy_pass_request_body off;
proxy_pass http://10.68.3.23:8390;

location /pass {
          proxy_pass_request_body on;
    proxy_pass http://10.68.3.23:8388/$fn;
    }

location /download {
   proxy_pass http://10.68.3.23:8388/$fn;
  }

}#end of location /

}#server

```

server {

```
server_name transfer;
listen 8390;
proxy_ignore_client_abort on;

location / {
       set $loc "/pass";
 add_header "X-Accel-Redirect" $loc;
 return 301;
  }

}#backend server 1

```

server {  
server\_name storage;  
listen 8388;

```
location / {
            root /data;
 client_body_temp_path /data1/client_tmp;

 dav_methods PUT DELETE MKCOL COPY MOVE;

 create_full_put_path on;
 dav_access user:rw group:rw all:rw;

              limit_except GET {
   allow all;
   }
}

```

}#backend server 2

}#http

* * *

when i put one file to test, while sending to the first upstream  
server(backend 1), the connection closed.  
why ?

Thanks.

---

<div class="post-metadata">

**Author:** ![Yu.Cheung](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/ce73a5/32.png) [@Yu.Cheung](https://www.ruby-forum.com/u/Yu.Cheung)\
**Post date:** [April 21, 2009, 11:42am UTC](https://www.ruby-forum.com/t/why-client-closed-prematurely-connection-while-sending-request-to-upstream/166024/2 "2009-04-21T11:42:22Z")

</div>

it seems because the body size does not match the size  
"Content-Length: " defined.  
when the content-length is the body’s size, it will be ok.  
but i tried the wrong length in the request header, the ‘client closed  
…’ came… [ I just want to make sure whether it will work in this  
way, for security ]  
I am not sure about this.  
but this working way is what i need. 🙂

2009/4/21 Yu.Cheung [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
