# Using Nginx with chunking

**URL:** <https://www.ruby-forum.com/t/using-nginx-with-chunking/242976>\
**Category:** NGINX\
**Created:** [August 12, 2015, 11:31am UTC](https://www.ruby-forum.com/t/using-nginx-with-chunking/242976 "2015-08-12T11:31:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [August 12, 2015, 11:31am UTC](https://www.ruby-forum.com/t/using-nginx-with-chunking/242976/1 "2015-08-12T11:31:13Z")

</div>

Hello,

I have nginx configured to send files in chunks to remote clients. The  
clients will contact the server to send it in chunks of 1 MB each. I am  
using nginx version 1.8.0

[root@ph-rdu-external-download-01 sbin]# ./nginx -V

nginx version: nginx/1.8.0

built by gcc 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC)

built with OpenSSL 1.0.1e-fips 11 Feb 2013

TLS SNI support enabled

configure arguments: --user=nginx --group=nginx  
–prefix=/usr/local/nginx --lock-path=/var/lock/subsys/nginx  
–with-ld-opt=-Wl,-rpath,/usr/lib64 --with-debug  
–add-module=/root/integ/ngx\_devel\_kit-master/  
–add-module=/root/integ/lua-nginx-module-0.9.15  
–error-log-path=/var/log/nginx/error.log  
–http-log-path=/var/log/nginx/access.log  
–without-http\_autoindex\_module --without-http\_fastcgi\_module  
–with-http\_ssl\_module --without-http\_geo\_module  
–without-http\_empty\_gif\_module --without-http\_ssi\_module  
–without-http\_userid\_module --without-mail\_pop3\_module  
–without-mail\_imap\_module --without-mail\_smtp\_module  
–without-http\_uwsgi\_module --without-http\_scgi\_module  
–with-http\_realip\_module --with-http\_gzip\_static\_module  
–with-http\_stub\_status\_module --with-ipv6

Currently I am running into an issue, where if the last chunk size is  
very small (few bytes), the server doesnt seem to the send the chunk  
correctly because of which the clients would re-try again for the same  
chunk. For some reason it is not able to send the last chunk. I have  
attached the debug logs to the thread. If you see the logs the last  
three writes seem to be for the same chunk of size 6672 bytes

However if the last chunk size relatively large, then download succeeds  
without any issues. The issue is seen when the last chunk size is very  
small.

My current nginx configuration is as follows

http {

```
    # Logging format

    log_format main '$remote_addr - $remote_user [$time_local] ' 

```

'"$request\_length" “$request\_time” ’

```
'"$request" $status $bytes_sent ' '"$body_bytes_sent" "$bytes_sent" 

```

';

```
    default_type application/octet-stream;

    include mime.types;

    keepalive_timeout 300 300;

    keepalive_requests 8000;

    charset utf-8;

    source_charset utf-8;

    # Check if it makes errors.

    ignore_invalid_headers off;

    recursive_error_pages on;

    sendfile on;

    server_tokens off;

    tcp_nodelay on;

    tcp_nopush off;

```

}

Regards,  
Arun

---

<div class="post-metadata">

**Author:** ![Arun\_John\_Sarujohn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d07c76/32.png) [@Arun\_John\_Sarujohn](https://www.ruby-forum.com/u/Arun_John_Sarujohn)\
**Post date:** [August 12, 2015, 2:53pm UTC](https://www.ruby-forum.com/t/using-nginx-with-chunking/242976/2 "2015-08-12T14:53:20Z")

</div>

Hello!

On Wed, Aug 12, 2015 at 09:30:15AM +0000, Arun John (arujohn) wrote:

> Hello,
> 
> I have nginx configured to send files in chunks to remote  
> clients. The clients will contact the server to send it in  
> chunks of 1 MB each. I am using nginx version 1.8.0

You confuse chunks and range requests. These are distinct things  
in HTTP.

> Currently I am running into an issue, where if the last chunk  
> size is very small (few bytes), the server doesn’t seem to the  
> send the chunk correctly because of which the clients would  
> re-try again for the same chunk. For some reason it is not able  
> to send the last chunk. I have attached the debug logs to the  
> thread. If you see the logs the last three writes seem to be for  
> the same chunk of size 6672 bytes

What makes you think that the problem is with nginx, and not with  
the client?

–  
Maxim D.

> **[nginx](http://nginx.org/)**

---

<div class="post-metadata">

**Author:** ![Arun\_John\_Sarujohn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d07c76/32.png) [@Arun\_John\_Sarujohn](https://www.ruby-forum.com/u/Arun_John_Sarujohn)\
**Post date:** [August 12, 2015, 3:05pm UTC](https://www.ruby-forum.com/t/using-nginx-with-chunking/242976/3 "2015-08-12T15:05:36Z")

</div>

Hi Maxim,

Sorry for the confusion.

But even for range requests, it should return the bytes requested,  
correct? Am I missing any configuration?

Regards,  
Arun

On 8/12/15, 6:23 PM, “nginx on behalf of Maxim D.”

---

<div class="post-metadata">

**Author:** ![Arun\_John\_Sarujohn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d07c76/32.png) [@Arun\_John\_Sarujohn](https://www.ruby-forum.com/u/Arun_John_Sarujohn)\
**Post date:** [August 12, 2015, 3:44pm UTC](https://www.ruby-forum.com/t/using-nginx-with-chunking/242976/4 "2015-08-12T15:44:09Z")

</div>

> If you see the logs the last three writes seem to be for the same chunk of  
> size 6672 bytes

I imagine this is a typo (and not what the client expects) because the  
length is 6272 bytes.

> But even for range requests, it should return the bytes requested,  
> correct? Am I missing any configuration?

Well you can always try to test it with something like curl to see if  
the  
problem is not really on the particular client:

curl --header “Range: bytes=16777216-16783487” [http://yourfile](http://yourfile)  
or  
curl -r 16777216-16783487 [http://yourfile](http://yourfile)

There are some SSL errors in the debuglog though.

rr

---

<div class="post-metadata">

**Author:** ![Arun\_John\_Sarujohn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d07c76/32.png) [@Arun\_John\_Sarujohn](https://www.ruby-forum.com/u/Arun_John_Sarujohn)\
**Post date:** [August 12, 2015, 4:24pm UTC](https://www.ruby-forum.com/t/using-nginx-with-chunking/242976/5 "2015-08-12T16:24:28Z")

</div>

Hello!

On Wed, Aug 12, 2015 at 01:05:13PM +0000, Arun John (arujohn) wrote:

> But even for range requests, it should return the bytes requested,  
> correct? Am I missing any configuration?

The question is the same: what makes you think that nginx doesn’t  
return bytes requested? As per logs you’ve provided, everything  
is correctly returned to the client.

–  
Maxim D.

> **[nginx](http://nginx.org/)**
