CentOS 7
lnmp 1.16.1
Nginx环境搭建(基于lnmp环境)
不懂怎么安装Nginx,so用lnmp,虽然多安装了其他用不上程序,但省事。
lnmp怎么安装 见 https://lnmp.org/
安装成功后
安装时生成的解压文件夹lnmp1.6.先别删除!!!
安装Nginx的扩展nginx-rtmp-module模块
//下载扩展包 提示git没安装请安装git (yum install git)
git clone https://github.com/arut/nginx-rtmp-module.git
//为nginx创建扩展模块目录
mkdir /usr/local/nginx/extend_module
//为nginx创建hls临时存放地址
mkdir /usr/local/nginx/extend_module/hls
//将下载的nginx-rtmp-module目录移动到nginx扩展模块目录下
nginx-rtmp-module
mv / /usr/local/nginx/extend_module/nginx-rtmp-module
//查看nginx配置参数
nginx -V
//复制configure arguments:后的所有参数!
--user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --with-stream --with-stream_ssl_module --with-openssl=/root/lnmp1.6/src/openssl-1.1.1d --with-openssl-opt='enable-weak-ssl-ciphers'
//关闭nginx、php-fpm服务
//关闭nginx
service nginx stop
//关闭php-fpm
service php-fpm stop
//进入安装时生成的文件夹:lnmp1.16/lnmp1.16.1/src (在目录下用 ls命令查看下,没lnmp1.6目录,可能lnmp文件没解压)
//解压nginx源码包
tar -xzvf nginx-1.11.1.tar.gz
//进入nginx源码目录
cd nginx-1.16.1
//安装rtmp扩展模块
./configure 刚才复制的nginx configure参数 --add-module=rtmp扩展包目录
如:
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --with-stream --with-stream_ssl_module --with-openssl=/root/lnmp1.6/src/openssl-1.1.1d --with-openssl-opt='enable-weak-ssl-ciphers' --add-module=/usr/local/nginx/extend_module/nginx-rtmp-module
//编译
make
(如果提示/root/lnmp1.6/src/openssl-1.1.1d: No such file or directory错误,返回src上层目录把openssl-1.1.1d.tar.gz解压再次编译)
//安装
make install
不知道什么原因总提示有错误,小白也不知道怎么查原因,so 改用nginx-http-flv-module,nginx-http-flv-module有nginx-rtmp-module所有功能
//下载扩展包 提示git没安装请安装git
git clone https://github.com/arut/nginx-http-flv-module.git
//将下载的nginx-rtmp-module目录移动到nginx扩展模块目录下
nginx-http-flv-module
mv / /usr/local/nginx/extend_module/nginx-rtmp-module
//安装rtmp扩展模块
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --with-stream --with-stream_ssl_module --with-openssl=/root/lnmp1.6/src/openssl-1.1.1d --with-openssl-opt='enable-weak-ssl-ciphers' --add-module=/usr/local/nginx/extend_module/nginx-http-flv-module
//编译
make
//安装
make install
//重启nginx
service nginx start
service php-fpm start
//查看安装状态
nginx -V
看到
--user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --with-stream --with-stream_ssl_module --with-openssl=/root/lnmp1.6/src/openssl-1.1.1d --with-openssl-opt='enable-weak-ssl-ciphers' --add-module=/usr/local/nginx/extend_module/nginx-http-flv-module
表示安装成功
配置rtmp
进入cd /usr/local/nginx/conf 目录
//编辑配置 vim nginx.conf
#尾部加入
rtmp {
server {
listen 1935;
chunk_size 4000;
application nideyingyong {
live on;
record off;
hls on;
hls_path /usr/local/nginx/extend_module/hls;
hls_fragment 5s;
}
}
}
参数说明:
rtmp是协议名称
server 说明内部中是服务器相关配置
listen 监听的端口号, rtmp协议的默认端口号是1935
application 访问的应用路径是 hls
live on; 开启实时
record off; 不记录数据
在http里面加入,不要在底部重新加入http
http {
server {
listen 8080;
location /nideyingyong {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /tmp;
add_header Cache-Control no-cache;
}
}
}
保存修改后:nginx -s reload //重载下nginx配置
服务器开放1935端口 (如服务器防火墙已关闭跳过此步)
//开放1935端口 /sbin/iptables -I INPUT -p tcp --dport 1935 -j ACCEPT //保存配置 /etc/rc.d/init.d/iptables save //重启服务 /etc/rc.d/init.d/iptables restart //查看端口开放状态 /etc/init.d/iptables status
用 obs 推流
地址 rtmp://你服务器IP或域名:1935/nideyingyong/stream
后面的stream 随意下
用VLC播放
地址 rtmp://你服务器IP或域名:1935/nideyingyong/stream