Ubuntu16.04下配置nginx HTTPS + RTMP流媒體伺服器
阿新 • • 發佈:2018-11-07
Ubuntu16.04下配置HTTPS + rtmp伺服器
1. 在/usr目錄下建立資料夾nginx-install:
cd /usr
mkdir nginx-install
cd nginx-install
2. 下載nginx及相關元件:
wget http://nginx.org/download/nginx-1.10.3.tar.gz wget http://zlib.net/zlib-1.2.11.tar.gz wget https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz wget https://www.openssl.org/source/openssl-1.0.2k.tar.gz wget https://github.com/arut/nginx-rtmp-module/archive/master.zip apt update apt install unzip apt-get installopenssl libssl-dev (CentOS環境下,使用:yum install openssl-devel)
3. 解壓4個tar.gz檔案、一個zip檔案(二選一):
1) tar同時解壓多個檔案(推薦):
for tar in *.tar.gz; do tar xvf$tar; done
unzip *.zip
2) tar在語法上不支援解壓多個檔案:
tar -zxvf nginx-1.10.3.tar.gz tar -zxvf zlib-1.2.11.tar.gz tar -zxvf pcre-8.40.tar.gz tar -zxvf openssl-1.0.2k.tar.gz unzip *.zip
4. 編譯安裝nginx:
注:如wget有改動記得修改下面檔案路徑
cd nginx-1.10.3
./configure --prefix=/usr/local/nginx--with-debug --with-pcre=../pcre-8.40 --with-zlib=../zlib-1.2.11--with-openssl=../openssl-1.0.2k --add-module=../nginx-rtmp-module-master --with-http_ssl_module
make
make install
5. 將證書檔案 *.crt 、私鑰檔案 *.key儲存到/usr/local/nginx/conf目錄下;
6. 配置nginx.conf,目錄/usr/local/nginx/conf:
vim /usr/local/nginx/conf/nginx.conf
1) rtmp配置:
文末位置填入:
rtmp {
server {
listen 1935; #監聽埠號
chunk_size 4096;
application vod {
play /var/flvs; #點播視訊目錄
}
application live{
live on;
}
application vod_http {
play 127.0.0.1:1935;
}
application vod_mirror {
play /var/local_mirror 127.0.0.1;
}
}
}
2) HTTPS配置:
在http標籤內,新增:
server {
listen 443;
server_name localhost;
ssl on;
ssl_certificate *.crt; #此處填證書檔名稱
ssl_certificate_key *.key; #此處填證書金鑰名稱
ssl_protocols TLSv1TLSv1.1 TLSv1.2;
ssl_session_timeout 5m;
ssl_ciphersECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
location / {
root /html;
index index.html index.htm index.php;
}
}
3) 用/usr/local/nginx/sbin/nginx -t測試配置是否正確;
4) 重啟nginx:
/usr/local/nginx/sbin/nginx -s reload
7. 出現open()"/usr/local/nginx/logs/nginx.pid" failed 的解決方法:
加-c引數,指定conf檔案目錄
/usr/local/nginx/sbin/nginx-c /usr/local/nginx/conf/nginx.conf