阿里云ECS云服务器Centos7搭建nginx +rtmp+nginx-http-flv-module 环境
参考了caowenjing123的博客
nginx +rtmp+nginx-http-flv-module 环境搭建
进行了一些归纳整理。
以下是搭建步骤:
1./opt下创建tools文件夹,将下载的nginx-1.14.2.tar.gz放在tools文件夹中
cd /opt
mkdir tools
cd tools
wget https://nginx.org/download/nginx-1.14.2.tar.gz
2./usr/local下创建nginx文件夹,git clone下载nginx-http-flv-module到nginx文件夹
cd /usr/local
mkdir nginx
cd nginx
git clone https://github.com/winshining/nginx-http-flv-module
3.就在tools文件夹下解压nginx-1.14.2.tar.gz,进入nginx-1.14.2目录
cd /opt/tools
tar -zxvf nginx-1.14.2.tar.gz
cd nginx-1.14.2
执行以下命令
./configure --prefix=/usr/local/nginx --add-module=/usr/local/nginx/nginx-http-flv-module
4.执行make && make install
make && make install
5.进入 /usr/local/nginx/conf ,修改配置文件
cd /usr/local/nginx/conf
vim nginx.conf
worker_processes 10;
events {
worker_connections 10240;
}
rtmp_auto_push on;
rtmp_auto_push_reconnect 1s;
rtmp_socket_dir /tmp;
rtmp{
out_queue 4096;
out_cork 8;
max_streams 128;
timeout 15s;
drop_idle_publisher 15s;
log_interval 5s;
log_size 1m;
server{
listen 1935;
application myapp{
live on;
record off;
gop_cache on;
}
application hls{
live on;
hls on;
hls_path /usr/local/nginx/html/hls;
hls_fragment 1s;
hls_playlist_length 3s;
}
application dash{
live on;
dash on;
dash_path /usr/local/nginx/html/dash;
}
}
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8002;
server_name 27.94.234.228;
location / {
root html;
index index.html index.htm;
}
location /live{
flv_live on;
chunked_transfer_encoding on;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
}
location /hls{
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /usr/local/nginx/html/hls;
add_header 'Cache-Control' 'no-cache';
}
location /dash {
root /usr/local/nginx/html/dash;
add_header 'Cache-Control' 'no-cache';
}
location /stat {
#configuration of push & pull status
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root /usr/local/nginx/nginx-http-flv-module;
}
location /control {
rtmp_control all; #configuration of control module of rtmp
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
6.开启nginx
cd /usr/local/nginx/sbin
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
我执行完后提示进程已经在运行,就kill了一遍这个进程,然后就恢复正常了。
7.去ECS安全组添加端口1935, 8002
8.搭建成功后去浏览器输入 云服务器公用ip:8002,就有下图: