Reputation: 1420
I setup a web server with Nginx, and I use nginx-gridfs module to access the Mongodb content and use http_mp4_module to play the mp3 file as stream on client, both above services are working fine standalone, but when I try to combine these two services, and try to access the mp3 file which stored in Mongodb and play it as stream on client, there is a 404 error appeared, this sounds that the http_mp4_module can not work with Gridfs, it needs a real file which existed in File System. Below are my Nginx configuration setting:
For accessing Mongodb content: (I can access the mp3 file with URL http:// myhost/voice/mp3/xxxxxx.mp3)
location /voice/mp3/ {
gridfs whatsup
field=filename
type=string
root_collection=storage.voice.mp3;
mongo localhost:27017;
}
For playing mp3 file on client as stream (I can play the mp3 with browser with URL http:// myhost/mp3/xxxxxx.mp3, the mp3 file is existed in file system)
location /mp3 {
root /var/www/html/;
mp4;
}
both above services are working fine, but when I combine them, it does not work, the configuration as below:
location /play/mp3 {
gridfs whatsup
field=filename
type=string
root_collection=storage.voice.mp3;
mongo localhost:27017;
mp4;
}
when I try access URL http:// myhost/play/mp3/xxxxxx.mp3 with browser and play with it, it shows me 404 error.
is there any idea to combine both services? or whether or not there is something I missed?
Upvotes: 1
Views: 4128
Reputation: 11
Some media players need the HTTP range request protocol, because of time seeking. Such players check whether the webserver supports the protocol, before playing the media.
The original nginx-gridfs module doesn't have the implementation of the range request. This quick hack patch adds the range request support, and I confirmed it solved the problem.
However, this implementation blocks the whole nginx process until one streaming finished. It is so bad for nginx, because blocking IO should be avoided in the event-driven architecture. So, I think we should use other implementations for serving large files or streaming medias, such as gidfs-fuse and the others node proxy.
Upvotes: 1
Reputation: 558
Instead of using gridfs-fuse to mount your gridfs to file system, check this : http://blog.vladimirm.com/2011/06/export-files-from-mongodb-gridfs-with-directory-paths/
This is a bash script that mount gridfs files to filesystem
usage :
create file called gridfs.sh ( put inside the bash script that you will find in the link ) .
run this command : $ ./gridfs.sh host database_name (this will mount files inside the directory you are in ) .
Upvotes: 2
Reputation: 3308
First, redirect your mongodb gridfs url to local filesystem, configure your nginx server like this:
location / {
root mp3;
mp4;
}
location /tushuo/voice/mp3/ {
rewrite ^/tushuo/voice/mp3/(.*) /$1;
}
Then, you can use gridfs-fuse to mount your mongodb gridfs to your local filesystem tree, so that nginx mp4 module can find it. (Note: you have to run nginx as root.)
sudo ./mount_gridfs --db=whatsup.storage.tushuo.voice --host=localhost --fsnode=mp3 -/usr/local/nginx/mp3/
Upvotes: 0