Home | Mirror | Search

3. GridFS

http://www.mongodb.org/display/DOCS/GridFS

GridFS 類似 MogileFS

3.1. nginx-gridfs

http://github.com/mdirolf/nginx-gridfs

		
yum -y install pcre-devel

wget http://nginx.org/download/nginx-1.2.3.tar.gz
tar zxvf nginx-1.2.3.tar.gz

./configure --prefix=/srv/nginx-1.2.3 \
--sbin-path=/srv/nginx-1.2.3/sbin/nginx \
--conf-path=/srv/nginx-1.2.3/conf/nginx.conf \
--user=www --group=www \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-mail --with-mail_ssl_module \
--with-file-aio \
--with-cc-opt='-O2 -g' \
--add-module=/usr/local/src/nginx-gridfs

make && make install
		
		

配置語法說明:

gridfs DB_NAME [root_collection=ROOT] [field=QUERY_FIELD] [type=QUERY_TYPE] [user=USERNAME] [pass=PASSWORD]

gridfs 表示告訴nginx伺服器要調用gridfs模組
root_collection= 指定Gridfs collection的首碼. 預設: fs
field= 指定用於查詢的欄位 可以是 _id 和 filename. 預設: _id
type= 指定查詢的類型,這裡支持 objectid, string 和int. 預設: objectid
user= 指定資料庫的用戶名. 預設: NULL, 可省略
pass= 指定資料庫的密碼. 預設: NULL, 可省略
		

Nginx配置檔案中的具體寫法:

location /images/ {
     gridfs images
     field=_id
     type=objectid;
     mongo 127.0.0.1:27017;
}
		

上傳圖片

sudo /srv/mongodb/bin/mongofiles put --host localhost --port 27017 --db images --local ~/photo.jpg --type jpg
		

在瀏覽器裡輸入http://localhost/images/photo.jpg 能顯示圖片就說明成功了

例 75.1. nginx-gridfs

#指定db為static,其它均為預設,預設伺服器為本地
location /static/ {

	gridfs static;

}

location /static/ {

        gridfs static
        field=filename
        type=string;
        mongo 127.0.0.1:27017;

}

location /static/ {
	gridfs static;
	    field=filename
	    type=string;
	mongo "foo"
	    172.16.1.1:27017
	    172.16.1.2:27017;

}

location /static/ {

    gridfs static
    root_collection=images
    field=_id
    type=int
    user=admin
    pass=pass;
    mongo 127.0.0.1:27017;

}
			

3.2. lighttpd-gridfs

https://bitbucket.org/bwmcadams/lighttpd-gridfs/src/

comments powered by Disqus