Score:0

Nginx return 200 instead of 206

cn flag

I have a setup of the Nginx server (openresty) that has large files. When a client wants a range file Nginx sends 200 back instead of 206.

This is the example of my curl test:

curl -v -I -r 0- -X GET http://172.29.22.11/myBigFile.bin
*   Trying 172.29.22.11:80...
* TCP_NODELAY set
* Connected to 172.29.22.11 (172.29.22.11) port 80 (#0)
> GET /myBigFile.bin HTTP/1.1
> Host: 172.29.22.11
> Range: bytes=0-
> User-Agent: curl/7.68.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Transfer-Encoding: chunked
Transfer-Encoding: chunked
< Connection: keep-alive
Connection: keep-alive
< Expires: Wed, 21 Dec 2022 09:10:00 GMT
Expires: Wed, 21 Dec 2022 09:10:00 GMT
< Cache-Control: max-age=31536000
Cache-Control: max-age=31536000
< Access-Control-Allow-Headers: *
Access-Control-Allow-Headers: *
< Access-Control-Allow-Origin: *
Access-Control-Allow-Origin: *
< myCacheStatus: HIT
myCacheStatus: HIT
< Pragma: public
Pragma: public
< Cache-Control: public
Cache-Control: public
 
< 
* Excess found: excess = 448 url =/myBigFile.bin A (zero-length body)
* Connection #0 to host 172.29.22.11 left intact

How can I define Nginx to return proper 206 on this?

----- Adding my configuration -----

        location / {
            internal;
            
            proxy_cache my_cache;
        
            proxy_cache_key $uri;

            # set the ceching time for 200 respinse -> to 7 days
            proxy_cache_valid 200 7d;

            # Clear flags I dont want
            more_clear_headers 'Access-Control-Allow-Headers';
            more_clear_headers 'Access-Control-Allow-Origin';
            more_clear_headers 'access*';
            more_clear_headers 'content-disposition';
            more_clear_headers 'Date';
            more_clear_headers 'x-proxy-cache';
            more_clear_headers 'Server';

            # add headers to handle CORS
            add_header Access-Control-Allow-Headers '*';
            add_header Access-Control-Allow-Origin '*';

            # to reduce Bandwisth I use compression
            gzip on;

            # set up the proxy, and instruct it to cech even if thre is no Cache-Control
            proxy_ignore_headers X-Accel-Expires Expires Cache-Control;
            proxy_cache_lock on;
            proxy_cache_lock_timeout 0s;
            proxy_cache_lock_age 200s;
            proxy_cache_use_stale updating;


            # the run reverse proxy
            proxy_pass      http://0.0.0.0:3000;

            # set local ceching on the client side currently we will start at 365 days
            expires 365d;
            add_header Pragma public;
            add_header Cache-Control "public";

        }
in flag
That should be the default setting. Please show your configuration.
jp flag
Possible duplicate https://serverfault.com/questions/965209/multipart-ranges-in-nginx-reverse-proxy
Meir avatar
cn flag
@GeraldSchneider I added the config
Meir avatar
cn flag
@AlexD The answers there wasn't good (use varnish/don't cache those requests)
in flag
So, nginx only acts as a reverse proxy. That means the problem is most probably your backend server, not nginx.
Meir avatar
cn flag
@GeraldSchneider how do I add nginX the functionality of returning 206 when the file is already cached? and how can I do that even if the backend server don't support that?
Meir avatar
cn flag
It's seems weird to me that for that reason I have to switch to varnish
djdomi avatar
za flag
you may wsnt to force caching on nginx. however if your service is listen on 0.0.0.0, its directly reachable from the internet, normally you use 127.0.0.1 instead 0.0.0.0
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.