注意:我是在現有的openresty上搭建,所以跟從頭裝有點不同,不過大同小異。
文末放上參考的鏈接。
1.創建一個文件夾,用來添加各種依賴(注意權限,我是直接創建在根目錄了)
sudo mkdir nginx_dependence
2.然后安裝下面依賴,注意,一定不要使用apt-get 安裝(因為后面在配置Nginx的時候,要提供這些依賴的源碼路徑)。
cd nginx-dependence
sudo wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz
sudo tar -zxvf pcre-8.40.tar.gz
cd pcre-8.40/
sudo ./configure
sudo make
sudo make install
cd nginx-dependence
sudo wget http://zlib.net/zlib-1.2.11.tar.gz
sudo tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11/
sudo ./configure
sudo make
sudo make install
cd nginx-dependence
sudo wget https://www.openssl.org/source/openssl-1.0.2q.tar.gz
sudo tar -zxvf openssl-1.0.2q.tar.gz
cd openssl-1.0.2q/
sudo ./configure
sudo make
sudo make install
注意:openssl這里我一開始用的1.1.0這個版本,結果發現make的時候會報錯,
所以去官網找的1.0.2q這個版本
cd nginx-dependence
wegt https://github.com/arut/nginx-rtmp-module/archive/master.zip
下載之后解壓 unzip master.zip
然后是下載openresty,保險起見,我下的跟現有服務器同一版本的openresty。
3.然后解壓,進入openresty解壓后的文件夾
./configure --prefix=/server/openresty/ --user=root --group=root --with-pcre=/nginx-dependence/pcre-8.40/ --with-zlib=/nginx-dependence/zlib-1.2.11 --with-openssl=/nginx-dependence/openssl-1.0.2q --with-http_ssl_module --add-module=/nginx-dependence/nginx-rtmp-module
make 注意:我是升級,所以make,不需要make install,如果是新安裝,則需要make install
4.備份現有nginx
cp /server/openresty/nginx/sbin/nginx /server/openresty/nginx/sbin/nginx.bak
5.替換nginx
cd /nginx-dependence/openresty-1.11.1/build/nginx-1.5.12/objs
注意里面的路徑,根據所下的openresty版本調整
cp nginx /server/openresty/nginx/sbin/nginx
6.配置rtmp
打開/server/openresty/nginx/conf/nginx.conf
將下面一段粘貼到http{}的上面。
rtmp {
server {
listen 1935;
chunk_size 4000;
application mylive {
live on;
record all;
record_path /home/live_record;
record_max_size 200M;
hls on;
hls_path /home/hls;
hls_fragment 1s;
hls_playlist_length 5;
allow play all;
}
application live{
live on;
}
}
7.然后啟動nginx
cd /server/openresty/nginx/sbin/
./nginx -t
./nginx
完成
然后就可以向rtmp://IP:1935/mylive/ 這個地址推流了。(IP使用當前服務器的公網IP)
參考地址:
1.https://blog.csdn.net/bvngh3247/article/details/80405423
2.https://www.cnblogs.com/wanghjun/p/9100552.html
3.https://www.cnblogs.com/kgdxpr/p/3804257.html