RTMP伺服器架設

      在〈RTMP伺服器架設〉中尚無留言

ubuntu 及 nginx 的安裝設定,請參考 https://mahaljsp.ddns.net/nginx/

RTMP設定

開啟 /etc/nginx/nginx.conf,新增藍色部份設定

events {
        use epoll;
        worker_connections 768;
        # multi_accept on;
}
http{
    client_max_body_size 20m;手動加入此段, 防止資料太大無法上傳
}
rtmp {
    server {
        listen 1935;
        application live {
            live on;
            hls on;
            wait_key on;
            hls_path /data/video/live;
            hls_fragment 10s;
            hls_playlist_length 60s;
            hls_continuous on;
            hls_cleanup on;
            hls_nested on;
            allow publish all;
            allow play all;
            record all ;
            record_path /data/video/record;
            record_max_size 1000m;
            record_suffix -%Y-%m-%d-%H.%M.%S.ts;
            record_unique on;
        }
    }
}

/data/video/live 是直播影片的目錄,/data/video/record 是儲存影片的目錄。RTMP 預設是使用 1935 port,所以請記得 ip 分享器的 1935 需指向伺服器的 ip。

靜態伺服器

連線到 RTMP 伺服器的網址如下 rtmp://ip/live,其中的 “/live” 是屬於靜態伺服器,指向 /data/video/live 目錄。請開啟 /etc/nginx/sites-available/default,新增如下藍色設定。

server{
        listen 443 ssl;
        listen [::]:443 ssl;
        ssl_certificate /etc/letsencrypt/live/mahaljsp.ddns.net/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/mahaljsp.ddns.net/privkey.pem;

        server_name mahaljsp.ddns.net;
        root /server/wordpress;
        index index.php index.html;
        add_header X-Frame-Options SAMEORIGIN;
        location ~* \.(ico|css|js|gif|jpe?g|png|ogg|ogv|svg|svgz|eot|otf|woff)(\?.+)?$ {
                expires max;
                log_not_found off;
        }
        location / {
                try_files $uri $uri/ /index.php?$args;
        }
        location ~* \.php$ {
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_split_path_info ^(.+\.php)(.*)$;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            }
        location /live {
                alias /data/video/live;
        }
        location /record {
                alias /data/video/record;
        }
}

重啟Nginx

請執行如下指令

sudo systemctl restart nginx

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *