mongodb中gridfs适合存放视频和高清图片等等超大文件(小的文件建议不要存在mongodb中);
下面是在centos下配置nginx来訪问mongodb中的mp4文件:
1:安装nginx-gridfs
git clone https://github.com/rjhunjhunwla/nginx-gridfs //假设不存在git:yum -y install git
cd nginx-gridfs/
git submodule init
git submodule update
2::安装nginx
yum -y install pcre-devel
yum -y install zlib-devel
./configure --prefix=/opt/nginx --add-module=/opt/software/nginx-gridfs
make
make install
3:配置nginx-gridfs:(參考:https://github.com/rjhunjhunwla/nginx-gridfs 相关的參数设置)
在nginx.conf文件里增加:
location /video {
gridfs dbname
root_collection=fs
field=filename
type=string
user=username
pass=passwd;
mongo 127.0.0.1:27017;
}
4:html中调用显示:(http://www.videojs.com/ 下载使用video.js)
<video class="video-js vjs-default-skin" controls width="640" height="264" preload="auto">
<source src="http://127.0.0.1/video/filename.mp4" type='video/mp4' />
</video>