本人下载的是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)