nginx配置与直播项目
1、Centos 7.x 或 6.8
1、第一步 装系统 7.x
2、第二步 远程登录系统 ssh
3、第三步 安装yum install -y wget
源码安装 wget下载
4、第四步 换源 Centos7 默认源 阿里云的
并更新源 建立缓存
5、第五步 工具
git
gcc 编译器==>GNU开源计划===>C C++ Java等(源代码 面向对象 面向过程 汇编==>机器语言)
二进制 010101010101
vi/vim 文本编辑器 g环境 k环境
make源码编译安装 makefile文件 编译你当前改变的文件 更新文件
make install
可执行文件/ exe 指定的目录中 /路径中 bin sbin /usr/local/
/usr/local/nginx/sbin/nginx
openssl ssh服务
加密 ssh 免密登录 依赖
6、建立一个目录 源码编译安装 /usr/local/ /opt/ 各种放
github
7、nginx-rtmp-module 安装Nginx的rtmp协议的扩展
PC端
移动端--->操作系统--->iOS
--->Android
|---->手机
|---->平板(电脑)
|---->智能设备---->手表
---->手环
---->眼镜/VR/AR/MR
---->互联网电视APP
---->机顶盒Android
---->智能家电
|---->区块链设备
|---->垃圾桶
|---->加湿器 路由器 电视 冰箱 洗机器 热水器 运动 手机挖矿等
ALL IN BLOCKCHAIN
8、解压缩 tar -xzvf
9、进入到Nginx目录里 进行配置
cd nginx-1.15.0
./configure --with-http_ssl_module --add-module=../nginx-rtmp-module
http_ssl_module模块/扩展/ http https 阿里云ssl证书 免费/淘宝 25 二级域名
nginx-rtmp-module 模块/扩展 用于推流
10、编译源码并安装
建立在 makefile文件
make
make install
或
make && make install
11、验证nginx安装成功
1./usr/local/nginx/sbin/nginx -V 查看版本号
2.直接启动
/usr/local/nginx/sbin/nginx
[root@liangshen sbin]# ./nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
3.80端口被占用
调错
L A M P Apache2.0 阿帕奇 WEB服务 80端口
4.通过80端口 浏览器的方式访问 nginx欢迎页面 表示成功
不是 就需要改nginx的默认端口 80 8080 9000 9090 8888等
5.防火墙的端口限制
12、修改Nginx的conf文件 配置rtmp端口 1935端口
/usr/local/nginx
rtmp{
17
18 server{
19
20 listen 1935;
21 chunk_size 5000;
22
23 application hls{
24 live on;开启实时直播 实况直播
record off; 不记录数据
//没有指定ts切片放在哪里
25 }
26
27 }
28
29 }
停止Nginx服务 /usr/local/nginx/sbin/nginx -s stop
启动并加载配置文件
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
[root@liangshen conf]# /usr/local/nginx/sbin/nginx
nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
出现如上信息就表示直播服务器已经搭建成功。
13、如何推流
1、OBS软件推流Mac Linux Windows(小白 非专业人士)
2、FFmpeg音频视频处理的库Mac Linux Windows Android iOS等 开发者
OBS推流
rtmp://主机ip地址:1935/oldboy_live room01
14、到/usr/local/nginx/html
hls 目录 如果没有就conf里没有配置 1935
http服务里需要指定 推流上来 hls产生的ts切片的目录
location /hls {
#server hls fragments
types{
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
alias /temp/hls;
expires -1;
}
调试
VLC视频播放器
5.1 拉流的过程 播放
/usr/local/nginx/html/hls ls命令
xxxx.m3u8
http://x.x.x.x/hls/xxxx.m3u8
XMPP协议
HLS协议 apple 研发
视频流--->TS切片--->3S--->85kb--->HTTP
N多个.ts
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:141
#EXT-X-TARGETDURATION:8
#EXTINF:8.333,
oldboy_live-141.ts
#EXTINF:8.334,
oldboy_live-142.ts
#EXTINF:8.333,
oldboy_live-143.ts
#EXTINF:8.333,
oldboy_live-144.ts
#EXTINF:8.334,
oldboy_live-145.ts
#EXTINF:8.333,
oldboy_live-146.ts
#EXTINF:8.333,
oldboy_live-147.ts
#EXTINF:8.334,
oldboy_live-148.ts
#EXTINF:8.333,
oldboy_live-149.ts
7、HLS 原生就支持
8、基于Flash HTTP协议 HTTPS访问443
谷歌浏览器Chrome 就会禁用Flash
9、Nginx+RMTP协议+HLS协议
推流--->拉流
=================================================================
------------------------------------------------------------
ngin obs直播项目
Nginx定义
nginx是一个开源,支持高性能,高并发的www服务和代理服务软件。
特点
具有高并发,占用资源少,功能丰富,具有反向代理负载均衡功能和缓存服务功能
项目步骤
下载
yum install wget
更新源
yum makecache
更新系统文件
yum update
下载
yum install git gcc make pcre-devel openssl-devel (装不上就分开一个一个装)
cd /usr/local
下载
git clone git://github.com/arut/nginx-rtmp-module.git
安装Nginx的rtmp协议的扩展
wget http://nginx.org/download/nginx-1.15.0.tar.gz
解压
tar xzf nginx-1.15.0.tar.gz
进入nginx目录里配置
cd nginx-1.15.0
./configure --with-http_ssl_module --add-module=../nginx-rtmp-module
编译源码冰安装
make && make install
验证nginx安装成功
/usr/local/nginx/sbin/nginx -V
直接启动
cd /usr/local/nginx/sbin
/usr/local/nginx/sbin/nginx
关闭防火墙
systemctl stop firewalld
systemctl status firewalld
cd /usr/local/nginx/conf
vim nginx.conf
11
12 events {
13 worker_connections 1024;
14 }
15
16 rtmp{
17
18 server{
19
20 listen 1935;
21 chunk_size 5000;
22
23 application hls{
24 live on;
25 hls on;
26 record off;
27 hls_path /usr/local/nginx/html/hls;
28 hls_fragment 3s;
29 }
30
31 }
32
33 }
34 http {
35 include mime.types;
36 default_type application/octet-stream;
37
38 #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
--------------------
58 #access_log logs/host.access.log main;
59
60 location / {
61 root html;
62 index index.html index.htm;
63 }
64 location /hls {
65 #server hls fragments
66 types{
67 application/vnd.apple.mpegurl m3u8;
68 video/mp2t ts;
69 }
70 alias /temp/hls;
71 expires -1;
72 }
73 #error_page 404 /404.html;
74
75 # redirect server error pages to the static page /50x.html
----------------------------
/usr/local/nginx/sbin/nginx -s stop
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
/usr/local/nginx/sbin/nginx
cd /usr/local/nginx/html
vim play.html
PC 端播放 HLS(.m3u8
) 视频
借助 video.js 和 videojs-contrib-hls
由于 videojs-contrib-hls 需要通过 XHR 来获取解析 m3u8 文件, 因此会遭遇跨域问题, 请设置浏览器运行跨域
>
// XMLHttpRequest cannot load http://xxx/video.m3u8. No 'Access-Control-Allow-Origin' header is presen
t on the requested resource. Origin 'http://192.168.198.98:8000' is therefore not allowed access.
// 由于 videojs-contrib-hls 需要通过 XHR 来获取解析 m3u8 文件, 因此会遭遇跨域问题, 请设置浏览器运行跨>
域
var player = videojs('hls-video');
player.play();
==================
检查
http://10.0.0.200/play.html