本人下載的是nginx-1.11.3.tar.gz版本,搭建nginx流媒體播放器時候先下載好nginx。
一、安裝nginx
1.解壓nginx
tar -zxvf nginx-1.11.3.tar.gz
2.進入解壓後的nginx文件,進行安裝
./configure --prefix=/usr/local/nginx --with-http_mp4_module --with-http_flv_module --with-pcre
make
make install
若出現出現錯誤,此刻說明nginx安裝完畢。
打開 nginx.conf配置文件,可以查看到nginx默認配置的端口爲:
server {
listen 80;
server_name localhost;
#charset koi8-r;
...
}
啓動nginx後,打開首頁能訪問到如下頁面說明nginx啓動成功
二、配置 mp4,flv,音頻等格式文件播放配置文件
location ~ \.flv$ {
flv;
root /home/data;
}
location ~ \.mp4$ {
mp4;
root /home/data;
mp4_buffer_size 1m;
mp4_max_buffer_size 5m;
}
location ~ .*\.(mp3|wav|mov|pcm|m4a)$ {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
root /home/data;
}
關鍵參數解釋說明:
localtion:請求地址最後匹配的是正則,如配置flv,mp4都會被解析到
root:後面存放文件的根目錄
配置結束後,重啓服務器。
測試:
在配置的root跟目錄分別放置mp4,flv,mp3等文件,使用如下地址進行對流媒體文件進行播放:
http://ip:port/文件名
安裝過程可能不太順利,簡單記錄本人安裝出現錯誤以及解決思路:
1.configure安裝報錯
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.
configure安裝出現類似錯誤的時候,需要你的系統安裝支持包,ubuntu系統執行如下命令進行安裝
sudo apt-get update
sudo apt-get install libpcre3 libpcre3-dev
sudo apt-get install openssl libssl-dev
2.make命令
src/core/ngx_murmurhash.c: In function ‘ngx_murmur_hash2’:
src/core/ngx_murmurhash.c:37:11: error: this statement may fall through [-Werror=implicit-fallthrough=]
h ^= data[2] << 16;
~~^~~~~~~~~~~~~~~~
src/core/ngx_murmurhash.c:38:5: note: here
case 2:
^~~~
src/core/ngx_murmurhash.c:39:11: error: this statement may fall through [-Werror=implicit-fallthrough=]
h ^= data[1] << 8;
~~^~~~~~~~~~~~~~~
src/core/ngx_murmurhash.c:40:5: note: here
這個不是安裝錯誤,可以忽略不計,解決辦法是進入安裝包nginx目錄:
/home/fengchao/nginx-1.11.3/objs
vi打開Makefile刪除掉-Werror即可
CC = cc
CFLAGS = -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g
CPP = cc -E
LINK = $(CC)