


NGINX configures rtmp server to implement rtmp and hls live broadcast
Introduction to my use of NGINX
First, the configuration:
<code><span>work_processes</span><span>4</span>; events{ <span>work_connections</span><span>1024</span>; } http{ <span>include</span> mime.types; <span>default_type</span> application/octet-stream; <span>sendfile</span><span>on</span>; <span>keepalive_timeout</span><span>65</span>; server{ <span>listen</span><span>80</span>; <span>server_name</span> localhost; <span>location</span> /{ <span>root</span> html; <span>insex</span> index.html index.htm; } <span>location</span> /hls{ <span>alias</span> /tmp/app; } <span>error_page</span><span>500</span><span>502</span><span>503</span><span>504</span> /50x.html; <span>location</span> = /50x.html{ <span>root</span> html; } } } rtmp{ server{ <span>listen</span><span>1935</span>; <span>chunk_size</span><span>4000</span>; <span>application</span> liaortmp{ <span>live</span><span>on</span>; } <span>application</span> hls{ <span>live</span><span>on</span>; <span>hls</span><span>on</span>; <span>hls_path</span> /tmp/app; <span>hls_frament</span><span>15s</span>; } } } </code>
Interpretation of the configuration
workprocesses and work_connections
work_processes: Start the process, usually set to an equal number of CPUs.
work_connections: The maximum number of concurrent connections for a single background worker process
http server configuration
- sendndfile: Specify whether nginx calls the sendfile function (zero copy mode) to output files. For ordinary applications, it must be set to on. If it is used for disk IO heavy load applications such as downloading, it can be set to off to balance disk and network I/O processing speeds and reduce system uptime.
- keepalive_timeout: connection timeout
- server
- listen: configuration Which port to listen to
- server_name: Define access using xxx, that is, the domain name corresponding to the IP
- loaction /: Default request
- error_page and the following location: Define the error prompt page
- location /hls: Define the request hls, I am here The statement here is that if you request an hls stream, you need to add m3u8 after the playback address. The slice of hls is obtained from /tmp/
app
. The app defines the
An example (about
- listen: Listening port
- application liaortmp: Configure rtmp normal push request here
- application liaohls: Configure rtmp push request here, play through hls mode, slices are placed in /tmp/
app
, This corresponds to the http configuration above. Whatever the app writes here, it will also be written at http. Live on: Switch the live broadcast mode, that is, one-to-many broadcast. hls on: Switch HLS in the application.
Now the simple configuration of nginx has been completed, /usr/local/conf/nginx The above configuration is stored in .conf.
- hls_path: Slice storage address
- hls_fragment: Slice size, set HLS segment length, the default is 5 seconds
)
-
rtmp streaming and rtmp playback
The above introduces the configuration of NGINX rtmp server to implement rtmp and hls live broadcast, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.
- Playing address: rtmp ://x.x.x.x:1935/liaortmp/liao
- rtmp push streaming and hls live streaming
- Push streaming address: rtmp://x.x.x.x:1935/liaohls/liao
- Playing address: rtmp://x.x.x.x :80/hls/liao
- can be replaced by anything.
liao
Reference1. Detailed description of Nginx configuration file
2. Nginx RTMP module nginx-rtmp-module command detailed explanation

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to configure an Nginx domain name on a cloud server: Create an A record pointing to the public IP address of the cloud server. Add virtual host blocks in the Nginx configuration file, specifying the listening port, domain name, and website root directory. Restart Nginx to apply the changes. Access the domain name test configuration. Other notes: Install the SSL certificate to enable HTTPS, ensure that the firewall allows port 80 traffic, and wait for DNS resolution to take effect.

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

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.

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.

The methods that can query the Nginx version are: use the nginx -v command; view the version directive in the nginx.conf file; open the Nginx error page and view the page title.

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".

Starting an Nginx server requires different steps according to different operating systems: Linux/Unix system: Install the Nginx package (for example, using apt-get or yum). Use systemctl to start an Nginx service (for example, sudo systemctl start nginx). Windows system: Download and install Windows binary files. Start Nginx using the nginx.exe executable (for example, nginx.exe -c conf\nginx.conf). No matter which operating system you use, you can access the server IP

Create a container in Docker: 1. Pull the image: docker pull [mirror name] 2. Create a container: docker run [Options] [mirror name] [Command] 3. Start the container: docker start [Container name]
