From e994889cbe38b0c3af71e00a241c9cf0ff3ed3a3 Mon Sep 17 00:00:00 2001 From: Hizkia Felix Winata Date: Thu, 27 Jan 2022 20:49:17 +0800 Subject: [PATCH] add sample nginx config --- scripts/nginx/README.md | 5 +++ scripts/nginx/restream.conf | 84 +++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 scripts/nginx/README.md create mode 100644 scripts/nginx/restream.conf diff --git a/scripts/nginx/README.md b/scripts/nginx/README.md new file mode 100644 index 0000000..fa90ba0 --- /dev/null +++ b/scripts/nginx/README.md @@ -0,0 +1,5 @@ +# nginx caching reverse proxy config + +Check the `restream.conf` file for a good-enough caching reverse proxy setup +with nginx. It should just work with the default nginx that ships with most +distros. diff --git a/scripts/nginx/restream.conf b/scripts/nginx/restream.conf new file mode 100644 index 0000000..0d0b211 --- /dev/null +++ b/scripts/nginx/restream.conf @@ -0,0 +1,84 @@ +# 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; + } +}