


How nginx uses the nginx-rtmp-module module to implement the live broadcast room function
System environment
wujianjun@wujianjun-work ~ $ uname -a linux wujianjun-work 4.10.0-37-generic #41~16.04.1-ubuntu smp fri oct 6 22:42:59 utc 2017 x86_64 x86_64 x86_64 gnu/linux
Software environment
obs(open broadcaster software) v20.0.1 (linux)
nginx version: nginx/1.13.6
built by gcc 5.4.0 20160609 (ubuntu 5.4.0-6ubuntu1~16.04.5)
built with openssl 1.0.2g 1 mar 2016
tls sni support enabled
configure arguments: –with-pcre=pcre-8.38 –add-module=nginx-rtmp-module-1.1.11
nginx obs installation and configuration installation obs
wujianjun@wujianjun-work ~ $ sudo add-apt-repository ppa:kirillshkrogalev/ffmpeg-next wujianjun@wujianjun-work ~ $ sudo apt-get update && sudo apt-get install ffmpeg wujianjun@wujianjun-work ~ $ sudo apt-get install obs-studio wujianjun@wujianjun-work ~ $ sudo add-apt-repository ppa:obsproject/obs-studio wujianjun@wujianjun-work ~ $ sudo apt-get update && sudo apt-get install obs-studio
nginx installs rtmp module
nginx-rtmp-module ( )
wujianjun@wujianjun-work ~ $ sudo apt-get install build-essential wujianjun@wujianjun-work ~ $ wget wget http://nginx.org/download/nginx-1.13.6.tar.gz wujianjun@wujianjun-work ~/nginx-1.13.6 $ wget https://github.com/arut/nginx-rtmp-module/archive/v1.1.11.tar.gz wujianjun@wujianjun-work ~/nginx-1.13.6 $ tar -xvf v1.1.11.tar.gz wujianjun@wujianjun-work ~/nginx-1.13.6 $ wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.38/pcre-8.38.tar.gz wujianjun@wujianjun-work ~/nginx-1.13.6 $ tar -xvf pcre-8.38.tar.gz wujianjun@wujianjun-work ~/nginx-1.13.6 $ ls -all 总用量 748 drwxr-xr-x 9 wujianjun wujianjun 4096 10月 15 11:39 . drwxr-xr-x 63 wujianjun wujianjun 4096 10月 15 11:33 .. drwxr-xr-x 6 wujianjun wujianjun 4096 10月 15 11:33 auto -rw-r--r-- 1 wujianjun wujianjun 282456 10月 10 23:22 changes -rw-r--r-- 1 wujianjun wujianjun 430416 10月 10 23:22 changes.ru drwxr-xr-x 2 wujianjun wujianjun 4096 10月 15 11:33 conf -rwxr-xr-x 1 wujianjun wujianjun 2502 10月 10 23:22 configure drwxr-xr-x 4 wujianjun wujianjun 4096 10月 15 11:33 contrib drwxr-xr-x 2 wujianjun wujianjun 4096 10月 15 11:33 html -rw-r--r-- 1 wujianjun wujianjun 1397 10月 10 23:22 license drwxr-xr-x 2 wujianjun wujianjun 4096 10月 15 11:33 man drwxrwxr-x 6 wujianjun wujianjun 4096 2月 13 2017 nginx-rtmp-module-1.1.11 drwxr-xr-x 7 wujianjun wujianjun 4096 11月 23 2015 pcre-8.38 -rw-r--r-- 1 wujianjun wujianjun 49 10月 10 23:22 readme drwxr-xr-x 9 wujianjun wujianjun 4096 10月 15 11:33 src wujianjun@wujianjun-work ~/nginx-1.13.6 $ ./configure --with-pcre=pcre-8.38 --add-module=nginx-rtmp-module-1.1.11 wujianjun@wujianjun-work ~/nginx-1.13.6 $ make && sudo make install wujianjun@wujianjun-work ~/nginx-1.13.6 $ ls -all /usr/local/nginx/ 总用量 24 drwxr-xr-x 6 root root 4096 10月 15 16:11 . drwxr-xr-x 11 root root 4096 10月 15 16:11 .. drwxr-xr-x 2 root root 4096 10月 15 16:11 conf drwxr-xr-x 2 root root 4096 10月 15 16:11 html drwxr-xr-x 2 root root 4096 10月 15 16:11 logs drwxr-xr-x 2 root root 4096 10月 15 16:11 sbin
Add rtmp protocol configuration
wujianjun@wujianjun-work ~/nginx-1.13.6 $ sudo vi /usr/local/nginx/conf/nginx.conf
Add the following rtmp protocol at the end of the nginx.conf file Configuration
rtmp { server { listen 1935; chunk_size 4096; application live { live on; record off; } } }
Start & test
Start nginx
wujianjun@wujianjun-work ~/nginx-1.13.6 $ sudo /usr/local/nginx/sbin/nginx
Start obs
Open the obs software you just installed, at the source Configure the push source of the image (I choose window capture here), click "Settings" in the lower right corner, and configure the stream push address as shown below
After the configuration is completed, click "Start Push" Stream"
Start a video player that supports network stream playback (the demonstration uses vlc player)
Configure the address for network stream playback, as shown below:
After clicking "Play", wait a few seconds and you will see the player displaying the image captured by obs.
Since the video stream needs to be transmitted over the network, there will be a delay of several seconds in the live image.
http access live video
1. Change the configuration in nginx.conf, add hls configuration (hls is the folder used to store streaming media in the streaming media server), and re-enter the directory where hls is located Just set the http protocol to access the directory. The changed configuration is as follows:
rtmp { server { listen 1935; chunk_size 4096; application live { live on; hls on; hls_path /usr/share/nginx/html/hls; hls_fragment 5s; } } } http { server { listen 80; ..... location / { #root html; root /usr/share/nginx/html; index index.html index.htm; } ..... } }
Note: The user of nginx in the directory where hls is located must have write permission.
2. Obs software configures the recording stream name
There is a place to set the "stream name" below the configuration of the obs push stream URL. You can fill in a name at will (I fill in the example here) "test")
3. Restart nginx and obs software. We can enter http://ip/hls/test.m3u8 in the mobile browser to play the live video on the mobile phone. (The live broadcast delay is a bit large, and the article will be optimized later)
The above is the detailed content of How nginx uses the nginx-rtmp-module module to implement the live broadcast room function. For more information, please follow other related articles on the PHP Chinese website!

NGINX is suitable for handling high concurrent requests, while Apache is suitable for scenarios where complex configurations and functional extensions are required. 1.NGINX adopts an event-driven, non-blocking architecture, and is suitable for high concurrency environments. 2. Apache adopts process or thread model to provide a rich module ecosystem that is suitable for complex configuration needs.

NGINX can be used to improve website performance, security, and scalability. 1) As a reverse proxy and load balancer, NGINX can optimize back-end services and share traffic. 2) Through event-driven and asynchronous architecture, NGINX efficiently handles high concurrent connections. 3) Configuration files allow flexible definition of rules, such as static file service and load balancing. 4) Optimization suggestions include enabling Gzip compression, using cache and tuning the worker process.

NGINXUnit supports multiple programming languages and is implemented through modular design. 1. Loading language module: Load the corresponding module according to the configuration file. 2. Application startup: Execute application code when the calling language runs. 3. Request processing: forward the request to the application instance. 4. Response return: Return the processed response to the client.

NGINX and Apache have their own advantages and disadvantages and are suitable for different scenarios. 1.NGINX is suitable for high concurrency and low resource consumption scenarios. 2. Apache is suitable for scenarios where complex configurations and rich modules are required. By comparing their core features, performance differences, and best practices, you can help you choose the server software that best suits your needs.

Question: How to start Nginx? Answer: Install Nginx Startup Nginx Verification Nginx Is Nginx Started Explore other startup options Automatically start Nginx

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

To shut down the Nginx service, follow these steps: Determine the installation type: Red Hat/CentOS (systemctl status nginx) or Debian/Ubuntu (service nginx status) Stop the service: Red Hat/CentOS (systemctl stop nginx) or Debian/Ubuntu (service nginx stop) Disable automatic startup (optional): Red Hat/CentOS (systemctl disabled nginx) or Debian/Ubuntu (syst

How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Notepad++7.3.1
Easy-to-use and free code editor