Implementation code of Nginx building rtmp live broadcast server

  • 2021-09-11 21:51:23
  • OfStack

1. Create a new rtmp directory in the nginx source directory, and enter git clone https://github.com/arut/nginx-rtmp-module.git

2. Recompile the nginx code as follows

./configure --prefix=/usr/local/nginx-1.2.9/ --add-module=./rtmp/nginx-rtmp-module --with-http_ssl_module --with-pcre=/lamp_source/pcre-8.38;
make;make install;
# Reinstall nginx

3. After the installation is completed.

Open nginx. conf Add the following code after http {server...}


rtmp{
    server{
        listen 1935;
        chunk_size 4000;
        application hls {
            live on;
            hls on;
            hls_path / Your server path, which is used to store cache files. Must be writable ;
            hls_fragment 5s;
        }
    }
}

Then create a new host configuration


server {
 
    listen 8851;
    location /index.html {
    root / Website storage directory ;
}
    location / {# return 403;
      # Serve HLS fragments
      types {
        application/vnd.apple.mpegurl m3u8;
        video/mp2t ts;
      }
      root / Ibid. for caching ;
      expires -1;
    }
  }

After completing the above configuration. Download a software called open broadcaster software to push the stream (note that ffmpeg can also be used to push the stream). Software use such as screenshots

Then click to start streaming.

Download and open vlc player (pull stream). Enter rtmp://Your URL: 1935/hls/Password in the picture above and ok. Successful live broadcast online


Related articles: