1. 用到的软件
1. Nginx
nginx是开源的web服务器
官网: nginx
2. Nginx-rtmp-module
nginx安装nginx-http-rtmp模块后可以提供rtmp协议的流媒体服务
Github地址: nginx-rtmp-module
3. Nginx-http-flv-module
nginx-http-flv-module是将rtmp协议转换为http协议的模块
Github地址: nginx-http-flv-module
4. OBS Studio
推流软件,向流服务器推流
5. flv.js
Flv.js 是 HTML5 Flash 视频(FLV)播放器,纯原生 JavaScript 开发,没有用到 Flash。由 bilibili 网站开源。
Github地址:flv.js
2. 安装Nginx和flv模块
1. 下载nginx源码压缩包
wget http://nginx.org/download/nginx-1.23.4.tar.gz
2. 解压
tar -zxvf nginx-1.23.4.tar.gz
3. 下载 nginx-http-flv-module并解压
这里使用gitcode的镜像源下载
wget https://gitcode.net/mirrors/winshining/nginx-http-flv-module/-/archive/master/nginx-http-flv-module-master.tar.gz
tar -zxvf nginx-http-flv-module-master.tar.gz
3.执行解压后nginx目录下的configure命令并并配置要安装的模板
–prefix: nginx安装的路径
nginx-http-flv-module已经包含了nginx-rtmp-module ,所以不需要在单独安装rtmp模块
./configure --prefix=/export/server/nginx --add-module=nginx-http-flv-module-master
可能会提示缺少库文件,执行命令下面安装即可,再重新执行 configure命令
./configure: error: the HTTP rewrite module requires the PCRE library.
yum -y install pcre-devel
./configure: error: SSL modules require the OpenSSL library.
yum -y install openssl-devel
4.编译,安装
make & make install
2. 配置nginx.conf文件并启动nginx
worker_processes 1;
events {
worker_connections 1024;
}
# 添加RTMP服务
rtmp {
server {
listen 1935;
chunk_size 4096;
application live {
live on;
}
}
}
http {
# 引入其他配置文件
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
# flv配置
location /live {
flv_live on;
chunked_transfer_encoding on; #open 'Transfer-Encoding: chunked' response
#出现跨域问题时加上这些
#add_header 'Access-Control-Allow-Credentials' 'true'; #add additional HTTP header
#add_header 'Access-Control-Allow-Origin' '*'; #add additional HTTP header
#add_header Access-Control-Allow-Headers X-Requested-With;
#add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
#add_header 'Cache-Control' 'no-cache';
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
启动nginx
./sbin/nginx
3. 开始推流
使用OBS进行推流
对应的拉流地址为
rtmp://192.168.242.130:1935/live/starship
使用flv进行拉流的地址为
http://192.168.242.130:80/live?port=1935&app=live&stream=starship