RTMP server + HLS Ubuntu 18.04.1 LTS

Install Nginx

sudo apt install libnginx-mod-rtmp

Install rtmp-module

sudo apt install libnginx-mod-rtmp
service nginx restart

Setting nginx conf
nano /etc/nginx/nginx.conf

rtmp {
    server {
        listen 1935;
        chunk_size 4000;
        allow play all;
        application live {
            allow play all;
            live on;
        application hls {
            live on;
            # Turn on HLS
            hls on;
            hls_path /mnt/hls/;
            hls_fragment 3;
            hls_playlist_length 60;
            # disable consuming the stream from nginx as rtmp
            deny play all;

Create new nginx config file
nano /etc/nginx/conf.d/hls.conf

server {
    listen 8080;

    location /hls {
        # Disable cache
        add_header Cache-Control no-cache;

        # CORS setup
        add_header 'Access-Control-Allow-Origin' '*' always;
        add_header 'Access-Control-Expose-Headers' 'Content-Length';

        # allow CORS preflight requests
        if ($request_method = 'OPTIONS') {
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Max-Age' 1728000;
            add_header 'Content-Type' 'text/plain charset=UTF-8';
            add_header 'Content-Length' 0;
            return 204;

        types {
            application/vnd.apple.mpegurl m3u8;
            video/mp2t ts;

        root /mnt;
        add_header Cache-Control no-cache;

Restart Nginx…Done

Basic uri syntax: rtmp://your_ip/hls/stream_name
video will be available as http://your_ip:8080/hls/stream_name.m3u8

Leave a Reply

Your email address will not be published. Required fields are marked *