HLS index and fragments randomly deleted

Author: bunjiboysCreated Feb 17, 2014Updated Dec 16, 2025

I am currently testing out nginx-rtmp and the only real problem I've been having is that every now and then, usually after 1-2 hours of streaming, all the .ts and the .m3u8 are deleted from the streaming folder. There are no reconnects from the source, and the rtmp_stat also shows that the source hasn't reconnected at all.

Configuration blocks added below

rtmp {
    server {
        listen 1935;
        ping 30s;
        notify_method get;
        on_connect http://localhost/ctrl/auth;

        application src {
            live on;
            hls on;

            hls_path /opt/sites/streams;
            hls_fragment 10s;
            hls_playlist_length 30s;
            hls_nested on;
            hls_fragment_slicing aligned;
            hls_type live;
        }
    }
}
server {
    listen 80;

    root /opt/sites/root;

    location = /favicon.ico {
        log_not_found off;
    }

    location = /ctrl/auth {
        allow 127.0.0.1;
        deny all;

        if ($arg_token = '<secret key>') {
            return 201;
        }
        return 403;
    }

    location = /stats/ {
        rtmp_stat all;
        rtmp_stat_stylesheet /stat.xsl;
    }

    location /streams/ {
        index index.m3u8;
        alias /opt/sites/streams/;
        types {
            application/vnd.apple.mpegurl m3u8;
        }

        add_header Cache-Control no-cache;
    }
}