本人小白一枚,基于个人经验,写一篇nginx搭建推流服务器的经验总结,互联网上基于linux环境下大家nginx推流的比较多,而基于Windows比较少,本篇文章纯属小白经验总结
操作也很方便简单,大家有兴趣可以跟着搭建一个
1.环境
系统环境:Windows Server 2008 r2
公司给我了一个以前的一个闲置主机让我配置搭建,环境如下
工具:nginx、nginx-rmtp-module、VLC播放器(手机也可以测试)、UE或者记事本都可
简介:Nginx是一款轻量级的Web服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,在BSD-like 协议下发行。其特点是占有内存少,并发能力强,事实上nginx的并发能力在同类型的网页服务器中表现较好,请自行百度了解,总之,可以用来做大家直播推流服务器环境
2. 准备下载文件
需要的配置文件,这里我就全部整理好了,
1)Nginx 下载
2)nginx-rmtp-module 下载
3)准备一段视频
我下载的分享百度云链接地址:
链接: pan.baidu.com/s/1eNXdIViv… 提取码: jr7y
3.搭建环境
将文件下载下来后,将nginx 1.7.11.3 Gryphon解压后的目录名改成nginx-1.7.11.3-Gryphon (这里我是放到E:\nginx-1.7.11.3-Gryphon的),nginx-rtmp-module文件解压后放到E:\nginx-1.7.11.3-Gryphon\nginx-rtmp-module
这个时候搭建工作基本已经完成了,剩下的就是修改配置了,但是在此之前我们还需要下载msvcr100.dll这个文件,因为在运行的时候会出现提示缺少这个文件无法运行的提示。
我百度了一下,只要下载好这个文件,x86版本的放到C:\WINDOWS\SYSTEM32下,x64版本放到C:\WINDOWS\SYSWOW64下,接着重启系统。我安装的是64位系统,所以放在C:\WINDOWS\SYSWOW64下,文件在百度云中
4.配置
下面来修改conf配置文件(配置文件位于E:\nginx-1.7.11.3-Gryphon\conf下)
复制nginx-win.conf文件,修改名称为nginx.conf,保存一定是UTF-8无BOM的,粘贴一下配置
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
rtmp{
server {
listen 1935;
chunk_size 4000;
#RTMP
application zhejiang10010 {
live on;
}
#HLS
# For HLS to work please create a directory in tmpfs (/tmp/app here)
# for the fragments. The directory contents is served via HTTP (see
# http{} section in config)
#
# Incoming stream must be in H264/AAC. For iPhones use baseline H264
# profile (see ffmpeg example).
# This example creates RTMP stream from zhejiang10010 ready for HLS:
#
# ffmpeg -loglevel verbose -re -i zhejiang10010.avi -vcodec libx264
# -vprofile baseline -acodec libmp3lame -ar 44100 -ac 1
# -f flv rtmp://localhost:1935/hls/zhejiang10010
#
# If you need to transcode live stream use 'exec' feature.
#
application hls {
live on;
hls on;
hls_path html/hls;
hls_fragment 5s;
}
}
}
http{
server {
listen 8765;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location /hls {
# Serve HLS fragments
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
alias hls;
expires -1;
add_header Access-Control-Allow-Origin *;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
5.最后启动nginx服务,
双击目录下的nginx.exe
推rtmp流:
rtmp://localhost:1935/hls/zhejiang10010
(localhost改成自己的公网IP地址)
按照截图填写参数
验证rtmp流推送情况:
vlc播放器输入:http://localhost:8765/html/hls/zhejiang10010.m3u8
或者手机打开该地址就可以看到推流的视频了,这样就成功了
(localhost改成自己的公网IP地址)
**写在最后 **
小小打个广告,大佬们公司如果有需要企业短信业务或者号码认证业务,可以看看这里,
浙江联通推出1元体验服务包,可以享受企业级服务号码认证一键登陆 企业短信会员通知 浙江联通官天猫旗舰店,点击了解详情
运营商的天猫店铺!服务好,一对一服务,没有中间商赚差价~