Skip to content

Instantly share code, notes, and snippets.

@pedro2555
Created March 18, 2021 12:53
Show Gist options
  • Save pedro2555/eb3a232df17bbd5ddce63611ea8df812 to your computer and use it in GitHub Desktop.
Save pedro2555/eb3a232df17bbd5ddce63611ea8df812 to your computer and use it in GitHub Desktop.
This is not a production config, this is from out lab environment. NGINX configuration to use as an MPEG-DASH edge caching system for use with Wowza Streaming Engine Live Streams. Ideally the caching zone should be entirely in ramfs or similar diskless filesystems.
user nginx;
worker_processes auto;
pid /var/run/nginx.pid;
worker_rlimit_nofile 1048576;
events {
worker_connections 1048576;
multi_accept on;
use epoll;
}
http {
# upstream
upstream wowza {
zone backend 64k;
ip_hash;
# omitted for security reasons, change in accordance with your environment.
server wowza.intra:1935;
}
# basic
sendfile on;
tcp_nopush on;
tcp_nodelay on;
server_tokens off;
keepalive_timeout 300s;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# ssl
ssl_ciphers "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.4.4 8.8.8.8 valid=300s ipv6=off;
resolver_timeout 10s;
# logs
log_format cache_st '$remote_addr - $upstream_cache_status [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';
access_log /var/log/nginx/cache.log cache_st;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
# gzip
gzip on;
gzip_disable "msie6";
gzip_http_version 1.1;
gzip_comp_level 6;
gzip_types text/plain text/css application/json application/javascript text/javascript application/x-javascript text/xml application/xml application/xml+rss application/vnd.ms-fontobject application/x-font-ttf font/opentype font/x-woff image/svg+xml image/x-icon;
# proxy
proxy_redirect off;
proxy_http_version 1.1;
proxy_read_timeout 10s;
proxy_send_timeout 10s;
proxy_connect_timeout 10s;
proxy_cache_path /var/cache/nginx/wowza_cache_temp use_temp_path=off keys_zone=wowza_cache_temp:10m max_size=20g inactive=10m;
proxy_cache wowza_cache_temp;
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;
proxy_cache_use_stale updating;
proxy_cache_background_update on;
# default route
server {
status_zone Wowza_Cache;
listen 80 default_server;
#listen 443 ssl default_server;
#ssl_certificate /path/to/cert.crt;
#ssl_certificate_key /path/to/cert.key;
add_header X-Cache-Status $upstream_cache_status;
# DASH Manifest
location ~ "(?<cache_key>\/(ZAP|ZAPR)\/(\d{4})\.stream_[\d\w]+\/manifest)(_w\d+)?\.mpd$" {
proxy_cache_key $cache_key;
proxy_cache_valid 200 302 10s;
proxy_pass http://wowza;
proxy_set_header Host $host:$server_port;
}
# DASH Chunk
location ~ "(?<cache_key>\/(ZAP|ZAPR)\/\d{4}\.stream_[\d\w]+\/chunk_ct(video|audio)_cfm4s_rid([\d\w]+)_(cs\d+|cinit))(_w\d+)?_mpd\.m4s$" {
proxy_cache_key $cache_key;
proxy_cache_valid 200 30s;
proxy_pass http://wowza;
proxy_set_header Host $host:$server_port;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment