# Sample configuration for HLS stream cache server worker_processes auto; events { worker_connections 128; } http { # Basic settings sendfile on; tcp_nopush on; tcp_nodelay on; server_tokens off; keepalive_timeout 300s; types_hash_max_size 2048; default_type application/octet-stream; # Set DNS resolver resolver 1.1.1.1 8.8.8.8 valid=300s ipv6=off; resolver_timeout 10s; # TODO: Update cache path to your cache directory proxy_cache_path /var/cache/nginx/restream use_temp_path=off keys_zone=restream_cache:10m max_size=20g inactive=10m; upstream restream { # TODO: Add your upstream here. For HTTP-only # upstreams, omit the :443, and change the # https:// to http:// in the proxy_pass directive. server stream.example.com:443; } # HTTPS configuration server { listen 443 ssl http2; listen [::]:443 ssl http2; # TODO: Add your server name here server_name example.com; ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; proxy_redirect off; proxy_http_version 1.1; proxy_read_timeout 10s; proxy_send_timeout 10s; proxy_connect_timeout 10s; proxy_cache restream_cache; proxy_cache_methods GET HEAD; proxy_cache_key $uri; proxy_cache_valid 200 302 5m; proxy_cache_valid 404 3s; proxy_cache_lock on; proxy_cache_lock_age 5s; proxy_cache_lock_timeout 1h; proxy_ignore_headers Cache-Control; proxy_ignore_headers Set-Cookie; # Optional: Add your custom headers here add_header X-Edge-Cache-Status $upstream_cache_status; add_header X-Edge-Region us-east; add_header X-Edge-Server my-server; location ~ \.(m3u8|mpd)$ { proxy_cache_valid 200 302 1s; proxy_pass https://restream; } location / { proxy_pass https://restream; } } # Optional: redirect all requests to https server { listen 80; listen [::]:80; server_name _; return 307 https://$server_name$request_uri; } }