Mongodb下GridFS使用及配合nginx实现文件服务
nginx--三方模块搭建图片服务器
1、前提环境
yum -y install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel git
wget https://nginx.org/download/nginx-1.7.4.tar.gz
/下载nginx
git clone https://github.com/rjhunjhunwla/nginx-gridfs
/下载第三方模块
2、准备配置
cd nginx-gridfs/
git submodule init && git submodule update
tar xf nginx-1.7.4.tar.gz
cd nginx-1.7.4
./configure --add-module=../nginx-gridfs /添加模块
make && make install
3、修改配置 vi /usr/local/nginx/conf/nginx.conf
server{
listen 80;
server_name localhost;
location /img/ {
gridfs test
field=filename
type=string;
mongo 127.0.0.1:27017
}
location / {
root html;
index index.html index.htm;
}
}
4、下载mongodb
vim /etc/yum.repos.d/mongodb-org-3.4.repo
[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
/添加下载库完成后
yum makecache
yum -y install mongodb-org
5、创建链接目录
mkdir /img
/rz 上传图片
/启动mongod数据库
systemctl restart mongod
mongofiles put --host 127.0.0.1 --port 27017 --db test 1.jpg --type jpg
/传输文件到数据库
6、去网络查看,输入完整路径
网友评论