Author: | Mike Dirolf <[email protected]> |
---|
nginx-gridfs is an Nginx module to serve content directly from MongoDB's GridFS.
nginx-gridfs requires the MongoDB C++ client library (which is installed by default when MongoDB is installed). It also needs to link against the boost libraries, since the MongoDB client depends on them.
Installing Nginx modules requires rebuilding Nginx from source:
Grab the Nginx source and unpack it.
Clone this repository somewhere on your machine.
Change to the directory containing the Nginx source.
Set environment variables:
$ export MONGO_INCLUDE_PATH=/path/to/mongodb/includes/ $ export LIBMONGOCLIENT=/path/to/libmongoclient/file $ export BOOST_INCLUDE_PATH=/path/to/boost/includes/ $ export LIBBOOST_THREAD=/path/to/libboost_thread/file $ export LIBBOOST_FILESYSTEM=/path/to/libboost_filesystem/file
For some versions of boost you'll need to set the following as well:
$ export LIBBOOST_SYSTEM=/path/to/libboost_system/file
Ideally there will be a better way to do this eventually, but this was easy to implement.
Now build:
$ ./configure --add-module=/path/to/nginx-gridfs/source/ $ make $ make install
Here is the relevant section of an nginx.conf:
location /gridfs/ { gridfs; gridfs_db my_app; # these are the default values: mongod_host 127.0.0.1:27017; gridfs_root_collection fs; }
The only required configuration variables are gridfs to enable the module for this location and gridfs_db to specify the database in which to store files. mongod_host and gridfs_root_collection can be specified but default to the values given in the configuration above.
This will set up Nginx to serve the file in gridfs with filename foo for any request to /gridfs/foo
- Some issues with large files
- Use mimetype stored in GridFS file (also maybe fall back to guessing by extension?)
- HTTP range support for partial downloads
- Use a single persistent connection
- URL decode filenames
- Better error handling / logging
- Better config / build process (just embed C driver?)
- Support for getting files by _id (in case there are duplicate filenames)
- Sho Fukamachi (sho) - towards compatibility with newer boost versions
nginx-gridfs is licensed under the Apache License, Version 2.0. See LICENSE for details.