Mac搭建nginx+rtmp服務器


原文:http://www.jianshu.com/p/02222073b3f1


簡介

nginx是非常優秀的開源服務器,用它來做hls或者rtmp流媒體服務器是非常不錯的選擇,本人在網上整理了安裝流程,分享給大家並且作備忘。

一、安裝Homebrow

已經安裝了brow的可以直接跳過這一步。
執行命令

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

如果已經安裝過,而想要卸載:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"

二、安裝nginx

先glone nginx項目到本地:

brew tap homebrew/nginx

執行安裝:

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

安裝過程比較緩慢,耐心等待
通過操作以上步驟nginx和rtmp模塊就安裝好了,下面開始來配置nginx的rtmp模塊

首先來看看我們的nginx安裝在哪裏了

brew info nginx-full

執行上面的命令後我們可以看到信息


nginx基本信息.01

nginx安裝所在位置

/usr/local/Cellar/nginx-full/1.10.1/bin/nginx

nginx配置文件所在位置

/usr/local/etc/nginx/nginx.conf

三、運行nginx

執行命令 ,測試下是否能成功啓動nginx服務

nginx

命令行如下圖所示

在瀏覽器地址欄輸入:http://localhost:8080 (直接點擊)
如果出現


Welcome to nginx!.03

代表nginx安裝成功了

如果終端上提示

nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)

則表示8080
端口被佔用了, 查看端口PID

lsof -i tcp:8080

kill掉佔用8080端口的PID

kill 9603(這裏替換成佔用8080端口的PID)

然後重新執行nginx

nginx常用方法:重新加載配置文件

nginx -s reload

重新加載日誌:

 nginx -s reopen

// 停止 nginx

nginx -s stop

// 有序退出 nginx

nginx -s quit

四、配置rtmp

現在我們來修改nginx.conf這個配置文件,配置rtmp
複製nginx配置文件所在位置

/usr/local/etc/nginx/nginx.conf

打開Finder Shift + command + G前往,用記事本工具打開nginx.conf

http {
    ……
}

在http節點後面加上rtmp配置:

rtmp {

  server {
      listen 1935;


    #直播流配置
      application rtmplive {
          live on;
      #爲 rtmp 引擎設置最大連接數。默認爲 off
      max_connections 1024;


       }


      application hls{

          live on;
          hls on;
          hls_path /usr/local/var/www/hls;
          hls_fragment 1s;
      }
   }
}

六、安裝ffmepg工具

brew install ffmpeg

安裝這個需要等一段時間等待吧 然後準備一個視頻文件作爲來推流,然後我們在安裝一個支持rtmp協議的視頻播放器,Mac下可以用VLC


VLC.04


顯示下圖表示ffmpeg安裝完畢


ffmpeg安裝完畢0.5

ffmepg 安裝完成後可以開始推流了



文/JIAAIR(簡書作者)
原文鏈接:http://www.jianshu.com/p/02222073b3f1
著作權歸作者所有,轉載請聯繫作者獲得授權,並標註“簡書作者”。

發佈了17 篇原創文章 · 獲贊 2 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章