nginx支持mongodb需要添加模块进行编译安装,步骤如下:

  • 安装pcre-devel 
    sudo apt-get install libpcre3 libpcre3-dev
    sudo apt-get install openssl libssl-dev

  • 安装nginx-gridfs
    git clone git://github.com/mdirolf/nginx-gridfs.git
    cd nginx-gridfs/
    git submodule init  


    git submodule update 


    cd /data/soft/nginx-1.6.2  (此处为下载好的nginx源码目录)


    ./configure --add-module=/data/soft/nginx-gridfs  (此处为上面git下载的gridfs的目录)


    make
    make install

  • 修改nginx的conf文件

  1. server {  

  2.         listen       80;  

  3.         server_name s1.111du.com;  

  4.   

  5.         //所有请求都映射到mongodb的服务中  

  6.         location / {  

  7.             //通过field=filename来做数据查询  

  8.             gridfs imark field=filename type=string;  

  9.             //mongodb的服务  

  10.             mongo 127.0.0.1:30001;  

  11.         }  

  12.   

  13.         # redirect server error pages to the static page /50x.html  

  14.         #  

  15.         error_page   500 502 503 504  /50x.html;  

  16.         location = /50x.html {  

  17.             root   html;  

  18.         }  

  19.   

  20.         # deny access to .htaccess files, if Apache's document root  

  21.         # concurs with nginx's one  

  22.         #  

  23.         location ~ /WEB-INF/ {  

  24.             deny  all;  

  25.         }  

  26.     }