Mac搭建nginx+rtmp服務器

Mac搭建nginx+rtmp服務器

概述

Mac安裝RTMP服務器過程記錄下來!nginx

1、安裝Homebrew

執行命令:git

1github

2ruby

3服務器

 

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

 

若是已經安裝過,而想要卸載:curl

1ui

2url

3spa

 

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

 

若是已經安裝過,則不用安裝!

2、安裝nginx

先glone nginx項目到本地:

1

2

3

 

brew tap homebrew/nginx

 

執行安裝:

1

2

3

 

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

 

經過操做以上步驟,nginx和rtmp模塊就安裝好了

3、運行nginx

執行命令:

1

2

3

 

nginx

 

出現以下頁面信息,表示nginx服務器搭建成功了,並且已經安裝了RTMP模塊了:

image

4、配置nginx和rtmp

下面開始來配置nginx的rtmp模塊。首先,咱們要看看nginx安裝到哪裏了:

1

2

3

 

brew info nginx-full

 

出現以下相似信息:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

 

==> Caveats

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.

 

nginx will load all files in /usr/local/etc/nginx/servers/.

 

- Tips -

Run port 80:

$ sudo chown root:wheel /usr/local/Cellar/nginx-full/1.10.0/bin/nginx

$ sudo chmod u+s /usr/local/Cellar/nginx-full/1.10.0/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 homebrew/nginx/nginx-full now and restart at login:

  brew services start homebrew/nginx/nginx-full

Or, if you don't want/need a background service you can just run:

  nginx

 

從這些信息中,能夠看到nginx.conf文件在:

1

2

3

 

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

 

nginx完整路徑:

1

2

3

 

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

 

經過如下打開nginx.conf配置文件來配置:

1

2

3

 

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

 

直接滾動到最後一行,以就是在http {} 以後:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

 

http {

    這裏默認就有的,不用管這些

}

 

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

rtmp {

    server {

        listen 5920;

        application rtmplive {

            live on;

            record off;

        }

    }

}

 

重啓nginx:

1

2

3

 

/usr/local/Cellar/nginx-full/1.10.0/bin/nginx -s reload

 

5、安裝ffmpeg

輸入如下命令來安裝ffmpeg:

1

2

3

 

brew install ffmpeg

 

安裝這個須要等一段時間,而後準備一個視頻文件做爲來推流,咱們在安裝一個支持rtmp協議的視頻播放器,Mac下能夠用VLC。

6、ffmpeg推流

1

2

3

 

ffmpeg -re -i /Users/huangyibiao/Desktop/test.mov -vcodec libx264 -acodec aac -f flv rtmp://localhost:5920/rtmplive/room

 

將視頻推流到服務器後,打開VLC,而後file->open network->輸入:

1

2

3

 

rtmp://localhost:5920/rtmplive/room

 

觀看視頻!

//查看 nginx

你能夠用這兩個命令,找安裝啓用的路徑 netstat -tnlp|grep nginx 而後看到一行記錄,複製最後的一個數據(進程ID) ps -aux |grep 進程ID 就能夠看到 NINGX的啓動方式了。 若是你如今不知道,而且沒重動NIGNX,則能夠 find /|grep nginx.conf
相關文章
相關標籤/搜索