通过Nginx模块搭建直播平台

手动构建自己的Nginx

根据METO大佬用Docker快速构建LEMP环境 一文中的Nginx,新增了对RTMP模块的支持,魔改了一般。代码托管于godu/nginx

  • 支持brotli模块,默认开启了
  • 支持rtmp模块,默认也开启了
# docker-compose.yaml
version: "3.7"
services:

  nginx:
    image:  hub.godu.dev/nginx
    container_name: nginx
    network_mode: host
    restart: always
    volumes: 
      - ./v:/v/rtmp/hls
      - ./etc/nginx/config/vs.conf:/etc/nginx/conf.d/default.conf

# vs.conf
server {
    listen       80;
    server_name  localhost;
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    location /hls {
        types {
            application/vnd.apple.mpegurl m3u8;  
            video/mp2t ts;  
        }
        alias  /v/rtmp/hls;   
        expires -1;
        add_header Cache-Control no-cache;  
    }
}

直播

使用OBS推流。

自定义流媒体服务器 rtmp://<ip:1935>/hls

推荐阅读