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 playbackThe 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