upstream data {
    server data.zap.stream;
}

server {
    listen 80;
    listen [::]:80;
    listen 443 ssl;
    listen [::]:443 ssl;

    access_log off;
    server_name us0.edge.zap.stream;

    # For Proxy Cache.
    proxy_cache_valid 404 10s;
    proxy_cache_lock on;
    proxy_cache_lock_age 300s;
    proxy_cache_lock_timeout 300s;
    proxy_cache_min_uses 1;
    proxy_set_header Host data.zap.stream;
    proxy_set_header X-Real-IP $remote_addr;
    ssl_certificate /etc/letsencrypt/live/us0.edge.zap.stream/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/us0.edge.zap.stream/privkey.pem;

    location ~ /.+/.*\.(m3u8)$ {
        proxy_pass http://data$request_uri;
        # For Proxy Cache.
        proxy_cache srs_cache;
        proxy_cache_key $scheme$proxy_host$uri$args;
        proxy_cache_valid 200 302 10s;
        proxy_hide_header 'Access-Control-Allow-Origin';
        add_header 'Access-Control-Allow-Origin' '*' always;
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
        add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
        add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
    }
    location ~ /.+/.*\.(ts)$ {
        proxy_pass http://data$request_uri;
        # For Proxy Cache.
        proxy_cache srs_cache;
        proxy_cache_key $scheme$proxy_host$uri;
        proxy_cache_valid 200 302 60m;
        proxy_hide_header 'Access-Control-Allow-Origin';
        add_header 'Access-Control-Allow-Origin' '*' always;
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
        add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
        add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
    }
    location / {
        root /usr/share/nginx/html;
        try_files $uri $uri/ =404;
    }
}