0

I want to deploy such a scenario:

  1. Client sends start-index and last-index headers to the nginx. these headers indicate the range of the file the user wants.
  2. Nginx must proxy the request to a file server and get back whole the file.
  3. Nginx should cache the whole file.
  4. Nginx must get back the requested range to the client. (in the start-index and last-index)
proxy_cache_path /var/cache/nginx/test levels=1:2 keys_zone=cdncache:10m max_size=10g use_temp_path=off;
proxy_cache_key $uri$slice_range;
proxy_cache_valid 200 302 5m;

log_format nginx_log '$uri|$body_bytes_sent|$time_iso8601|$status';

server {
    listen       80;
    server_name  cdnrb1.iranlms.ir;

    ssl_certificate "/etc/pki/nginx/cdn/cdn.cert";
    ssl_certificate_key "/etc/pki/nginx/cdn/cdn.key";
    ssl_session_cache shared:SSL:1m;
    ssl_session_timeout  10m;
    ssl_ciphers HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers on;

    proxy_cache_lock on;
    proxy_cache_lock_age 15s;
    proxy_cache_lock_timeout 5m;

    location /test {
      proxy_cache cdncache;
      proxy_cache_valid 200 1d;
      proxy_ignore_headers    X-Accel-Expires Expires Cache-Control;
      add_header X-Cache-Status $upstream_cache_status;
      add_header Accept-Ranges bytes;
      add_header Range $http_range;

      #add_header Range bytes=$http_start_index-$http_last_index

      resolver 127.0.0.11; # docker dns resolver
      proxy_pass http://10.212.192.40:8082/output.txt;
      access_log /var/log/nginx/cdn_access.log nginx_log;
    }
}

If I send -r option along with the curl command (curl -r 0-100 ...) I only get the requested part of the file. also, I know that add_header directive adds headers to the response. So I want to know how can I add some headers exactly to the client request. Or how can I send back the specified ranges to the user?

Emad Helmi
  • 652
  • 8
  • 25

0 Answers0