Introduction to my use of NGINX
First, the configuration:
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; } } }
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