1.購買一臺阿里云服務器脏答,配置centos7.2 64位
2.安裝擴展(#號后表示控制臺命令)
#yum -y install gcc gcc-c++ ncurses-devel perl zlib zlib-devel openssl openssl-devel pcre-devel unzip zip git
3.下載nginx,rtmp源碼
#wget http://nginx.org/download/nginx-1.9.15.tar.gz
#wget https://github.com/arut/nginx-rtmp-module/archive/master.zip
3.解壓
#tar -zxvf nginx-1.9.15.tar.gz
#unzip master.zip
4.編譯安裝nginx
#cd nginx-1.9.15
#./configure--with-http_ssl_module--add-module=../nginx-rtmp-module-master
#make
#make install
5.測試nginx
啟動nginx
#/usr/local/nginx/sbin/nginx
瀏覽器訪問你的IP地址,如果出現(xiàn)nginx歡迎界面倡勇,安裝成功
6.配置rtmp模塊
#vi /usr/local/nginx/conf/nginx.conf
6.1配置主播推流端口著觉,代碼在圖下面
rtmp {
server {
listen 1935;
chunk_size 4096;
application live {
live on;
record off;
hls on;
#on_publish http://127.0.0.1/auth_client.php;
hls_path /tmp/hls;
hls_fragment 2s;
}
}
}
6.2配置觀眾觀看端口村生,代碼在圖下面
直接把以下代碼復制到配置中,跟server同級-----START
upstream hls {
server 127.0.0.1:8080;
}
server {
listen 8080;
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root /root/nginx-rtmp-module-master/stat.xsl/;
}
location /hls {
# Serve HLS fragments
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /tmp;
add_header Cache-Control no-cache;
}
location /dash {
# Serve DASH fragments
root /tmp;
add_header Cache-Control no-cache;
}
location /control {
rtmp_control all;
}
error_page 500 502 503 504 /50x.html;
location = /50.html {
root html;
}
}
直接把以上代碼復制到配置中饼丘,跟server同級-----END
#以下代碼配置在80端口趁桃,為反向代理到hls,
location /hls {#這個hls是訪問url中的http://IP/hls/XXX
proxy_pass http://hls;#這個hls是與upstream中一樣的肄鸽,與url中hls無關卫病,可以與url中不一樣
}
6.3配置好后重啟nginx
6.3.1關閉后重啟
#/usr/local/nginx/sbin/nginx -s stop
#/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
6.3.2直接重啟
#/usr/local/nginx/sbin/nginx -s reload
7.測試直播
7.1主播推流
推薦用OBS,推流地址rtmp://IP:1935/live
串流碼隨便填典徘,用戶觀看哪個主播的地址后綴蟀苛,假設為live
7.2用戶觀看地址
瀏覽器訪問http://IP/hls/live.m3u8
如果沒有反向代理8080端口到hls,則地址是http://IP:8080/hls/live.m3u8
至次逮诲,直播搭建完成帜平,接下來將會講如何在此基礎上搭建PHP模塊,并監(jiān)聽主播的推流梅鹦。下一標題《LEMP服務器搭建二(PHP裆甩,MYSQL配置)》。
轉載請注明原作者及網(wǎng)址
直接把一下代碼復制到配置中齐唆,跟server同級-----START