0

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";

        }
Meir
  • 1
  • 1
  • That should be the default setting. Please show your configuration. – Gerald Schneider Dec 21 '21 at 09:29
  • Possible duplicate https://serverfault.com/questions/965209/multipart-ranges-in-nginx-reverse-proxy – AlexD Dec 21 '21 at 09:58
  • @GeraldSchneider I added the config – Meir Dec 21 '21 at 10:40
  • @AlexD The answers there wasn't good (use varnish/don't cache those requests) – Meir Dec 21 '21 at 10:41
  • So, nginx only acts as a reverse proxy. That means the problem is most probably your backend server, not nginx. – Gerald Schneider Dec 21 '21 at 10:43
  • @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 Dec 21 '21 at 10:51
  • It's seems weird to me that for that reason I have to switch to varnish – Meir Dec 21 '21 at 10:52
  • 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 – djdomi Dec 21 '21 at 12:16

0 Answers0