nginx 连接 mongodb

来源:互联网 发布:linux文件重命名 编辑:程序博客网 时间:2024/06/05 20:34
1)、 下载nginx-gridfs的代码
http://pan.baidu.com/s/1pKxgu1t

2)、安装 最新版  pcre
     从https://sourceforge.net/projects/pcre/files/pcre/ 下载最新版 pcre
     # unzip pcre-8.38.zip
     # cd pcre-8.38
     # ./configure --prefix=/usr/local/pcre-8.38 --libdir=/usr/local/lib/pcre --includedir=/usr/local/include/pcre
     # make && make install

3)、安装 nginx 
# yum -y install gcc* openssl*
# tar zxf nginx-1.7.7.tar.gz
# cd nginx-1.7.7
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-http_flv_module --with-http_gzip_static_module --add-module=/usr/src/nginx-gridfs --with-poll_module --without-select_module --with-http_realip_module --with-pcre=/usr/src/pcre-8.38
     此处编译的时候必须要指定 源码文件,否则会在 make 的时候报错:
/bin/sh: line 2: ./configure: No such file or directory 
make[1]: *** [/usr/local/pcre/Makefile] Error 127 
make[1]: Leaving directory `/usr/local/src/nginx-0.8.54′ 
make: *** [build] Error 2
# make && make install

4)、启动 nginx
# /usr/local/nginx/sbin/nginx
# ps -ef | grep nginx
# netstat -nlp | grep nginx
# curl http://localhost

显示欢迎页面,此时nginx 搭建成功

5)、配置 nginx 
# vim /usr/local/nginx/conf/nginx.conf
 location /pics/ {
                gridfs pics root_collection=fs field=filename type=string -upics -ppics;
                mongo 127.0.0.1:27017;
 }
6)、mongodb 上传图片
# mongofiles put 1.jpg -d pics -t jpg -upics -ppics
# mongofiles list -d pics -upics -ppics

7)、curl 下
curl http://localhost/pics/1.jpg
0 0
原创粉丝点击