rtmp推流nginx服务器环境搭建

Mac下命令行下homebrew进行安装nginx

一、安装 nginx

1:先更新homebrew

brew update

2: 查看nginx信息

brew search nginx

3:安装nginx

brew install nginx

 二、安装rtmp-module

1、nginx克隆的本地

$ brew tap denji/homebrew-nginx

2、安装nginx-full和rtmp

$ brew install nginx-full --with-rtmp-module

3、安装成功信息

🍺  /usr/local/Cellar/rtmp-nginx-module/1.1.7.11-dev_3: 94 files, 1.4MB, built in 2 seconds
==> Installing denji/nginx/nginx-full --with-rtmp-module
==> ./configure --prefix=/usr/local/Cellar/nginx-full/1.19.10 --with-http_ssl_module --with-pcre --with-ipv6 --sbin-path=
==> make install
==> Caveats
Docroot is: /usr/local/var/www

........
^ ==> Summary
🍺  /usr/local/Cellar/nginx-full/1.19.10: 8 files, 1.3MB, built in 25 seconds
==> Caveats
==> nginx-full
Docroot is: /usr/local/var/www


The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.
#配置路径为:/usr/local/etc/nginx/nginx.conf   端口:8080
nginx will load all files in /usr/local/etc/nginx/servers/.
#服务器容器在:/usr/local/etc/nginx/servers/

- Tips -
Run port 80:
 $ sudo chown root:wheel /usr/local/opt/nginx-full/bin/nginx
 $ sudo chmod u+s /usr/local/opt/nginx-full/bin/nginx
Reload config:
 $ nginx -s reload  重新加载配置
Reopen Logfile:
 $ nginx -s reopen  再次打开日志文件
Stop process:
 $ nginx -s stop    停止服务器
Waiting on exit process
 $ nginx -s quit    退出服务器

To have launchd start denji/nginx/nginx-full now and restart at login:
  brew services start denji/nginx/nginx-full
Or, if you don't want/need a background service you can just run:
  

nginx  启动nginx服务器
在浏览器中输入:http://localhost:8080/  进行测试

三、RTMP推流和HLS推流配置

在配置文件/usr/local/etc/nginx/nginx.conf 配置如下内容

rtmp{
    server{
        listen 1935;      #端口号:1935
        chunk_size 4000;
        application live{   #应用名:linx
            live on;
        }

        application hls{    #应用名:hls
            live on;
            hls on;
            hls_path /usr/local/var/www/hls;
            hls_fragment 1s;
        }
    }
}

server {
    listen       8080;
    server_name  localhost;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

   #支持rtmp
   location /stat{
           rtmp_stat all;
           rtmp_stat_stylesheet stat.xsl;
    }

    location /stat.xsl{
           root nginx-rtmp-module/;
    }

    location /control{
        rtmp_control all;
    }
    #支持rtmp

   #支持hls
   location /hls {
        #Serve HLS config
        types {
            application/vnd.apple.mpegurl m3u8;
            video/mp2t ts;
        }
        root /usr/local/var/www;
        add_header Cache-Control no-cache;
   }

 配置好后重新加载配置及测试

配置好后重新加载配置
(base) lwbdeMacBook-Pro:~ lwb$ nginx -s reload
(base) lwbdeMacBook-Pro:~ lwb$ nginx -s stop 
(base) lwbdeMacBook-Pro:~ lwb$ nginx 

测试rtmp推流
ffmpeg推流命令:
ffmpeg.exe -re -i path/xxx.mp4 -f flv rtmp://127.0.0.1:1935/live/123

vlc rtmp拉流播放: 媒体--》打开网络串流--》网络--》请输入网络URL:
rtmp://127.0.0.1:1935/live/123

测试hls推流:
ffmpeg -re -i  /Users/lwb/Desktop/测试视频/big_buck_bunny.mp4  -vcodec copy -f flv rtmp://192.168.1.101:1935/hls/room    
hls播放链接
http://192.168.1.101:8080/hls/room.m3u8

安装遇到问题:

1、在Mac上用 brew install nginx-full --with-rtmp-module 安装 nginxrtmp-module 报错 invalid option: --with-rtmp-module。

解决办法:https://www.jianshu.com/p/6698323836bf

2、下载失败错误

curl: (35) LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443 
Error: Failed to download resource "rtmp-nginx-module--patch"
Download failed: https://github.com/sergey-dryabzhinsky/nginx-rtmp-module/compare/v1.1.7.10..504b9ee.diff

解决办法:

方法1、host中,github.com相关的ip/域名映射记录(本人有效)

方法2:使用命令行移除git配置中 http/https代理

vim ~/.gitconfig
进行编辑移除后保存即可
移除一下内容
[http]
[https]

Window 下进行安装nginx 参考:

Windows10下nginx-1.18.0 + rtmp服务器搭建

https://blog.csdn.net/xiao_ma_nong_last/article/details/110826318

安装目录:D:\nginx\nginx 1.7.11.3 Gryphon

配置文件名:D:\nginx\nginx 1.7.11.3 Gryphon\conf/nginx-win.conf

先关闭
D:\nginx\nginx 1.7.11.3 Gryphon>nginx -s stop -c   conf/nginx-win.conf
再启动
D:\nginx\nginx 1.7.11.3 Gryphon>start nginx -c   conf/nginx-win.conf

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

gdliweibing

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值