: This article mainly introduces how to configure the rtmp Server for NGINX to implement rtmp and hls live broadcast. if you are interested in PHP Tutorial, refer to it. Introduction to NGINX
First configure:
work_processes4;events{ work_connections1024;}http{ include mime.types; default_type application/octet-stream; sendfileon; keepalive_timeout65; server{ listen80; server_name localhost; location /{ root html; insex index.html index.htm; } location /hls{ alias /tmp/app; } error_page500502503504 /50x.html; location = /50x.html{ root html; } } }rtmp{ server{ listen1935; chunk_size4000; application liaortmp{ liveon; } application hls{ liveon; hlson; hls_path /tmp/app; hls_frament15s; } } }
Explanation of configuration
Work_processes: starts a process, which is usually set to an equal number of CPUs.
Work_connections: maximum number of concurrent connections of a single backend worker process
Http server configuration
- Sendndfile: Specifies whether nginx calls the sendfile function (zero copy mode) to output files. for common applications, this function must be set to on. if this function is used for downloading application disk I/O heavy load applications, it can be set to off to balance the disk and network I/O processing speed and reduce the system uptime.
- Keepalive_timeout: connection timeout
- Server
- Listen: port used to configure the listener
- Server_name: the domain name corresponding to the IP address.
- Loaction/: default request
- Error_page and the following location: defines the error prompt page
- Location/hls: define the request hls. my declaration here is that if the request hls stream needs to be added to the stream playback address with m3u8, hls slice from/tmp/
app
Come on, the app is defined for itself
Configuration of rtmp streaming server
- Listen: listening port
- Application liaortmp: Configure rtmp normal streaming requests here
- Application liaohls: configure the rtmp streaming request here, play the video in hls mode, and place the slice in/tmp/
app
, Which corresponds to the http configuration above. what is written by the app here and what is written in http?
- Live on: switch the live broadcast mode, that is, one-to-multiple broadcast.
- Hls on: switch HLS in application
- Hls_path: slice storage address
- Hls_fragment: Slice size. set the length of HLS segments. the default value is 5 seconds.
So far, the simple configuration of nginx has been completed, and the above configuration is stored in/usr/local/conf/nginx. conf.
- Rtmp streaming and rtmp playback
- Streaming address: rtmp: // x. x: 1935/liaortmp/liao
- Playback address: rtmp: // x. x: 1935/liaortmp/liao
- Rtmp streaming and hls live broadcasting
- Streaming address: rtmp: // x. x. x: 1935/liaohls/liao
- Playback address: rtmp: // x. x: 80/hls/liao
liao
Can be replaced by any.
Reference
1. Nginx configuration file description
2. Nginx RTMP module nginx-rtmp-module instructions
The above describes how to configure the rtmp Server for NGINX to implement rtmp and hls live broadcast, including some content, and hope to help friends who are interested in PHP tutorials.