nginx mongo 和 gridfs 错误

发布于 2024-10-15 18:53:03 字数 1328 浏览 1 评论 0 原文

我试图将 gridfs/nginx/mongo 设置到位,但遇到一些奇怪的错误。

我在最新的 Ubuntu 上尝试使用 nginx 0.8.53 和 0.8.54 以及最新的 mongo 1.6.5 64 位。 使用 gridfs 模块编译效果很好: https://github.com/mdirolf/nginx-gridfs

server {
   listen xx.xx.xx.xx;
   server_name media.foo.com;

   access_log  /home/cloudy/log/nginx/media-access.log;
   error_log   /home/cloudy/log/nginx/media-error.log;

   location /gridfs/ {
       gridfs db_name;
       mongo 127.0.0.1:27017;
    }
}

我当我尝试获取文件时得到空响应:

curl -X GET -i 'http://media.foo.com/gridfs/4d4d526cea26b05041000015'
curl: (52) Empty reply from server

My error.log

2011/02/05 15:28:50 [alert] 7112#0: *1 zero size buf in writer t:0 r:0 f:0 0000000000000000 0000000000000000-0000000000000000 0000000000000000 0-0, client: 80.11.52.189, server: media.uk.cloudy.fr, request: "GET /gridfs/4d4d526dea26b05041000016 HTTP/1.1", host: "media.foo.com"
2011/02/05 15:28:52 [alert] 7112#0: *2 zero size buf in writer t:0 r:0 f:0 0000000000000000 0000000000000000-0000000000000000 0000000000000000 0-0, client: 80.11.52.189, server: media.uk.cloudy.fr, request: "GET /gridfs/4d4d526dea26b05041000016 HTTP/1.1", host: "media.foo.com"

欢迎任何建议:)

I was trying to put the gridfs/nginx/mongo setup in place but I am getting some strange errors.

I tried with nginx 0.8.53 and 0.8.54 and latest mongo 1.6.5 64bits on latest Ubuntu.
Compiling with gridfs module worked well: https://github.com/mdirolf/nginx-gridfs

server {
   listen xx.xx.xx.xx;
   server_name media.foo.com;

   access_log  /home/cloudy/log/nginx/media-access.log;
   error_log   /home/cloudy/log/nginx/media-error.log;

   location /gridfs/ {
       gridfs db_name;
       mongo 127.0.0.1:27017;
    }
}

I get an empty response when I try to fetch a file:

curl -X GET -i 'http://media.foo.com/gridfs/4d4d526cea26b05041000015'
curl: (52) Empty reply from server

My error.log

2011/02/05 15:28:50 [alert] 7112#0: *1 zero size buf in writer t:0 r:0 f:0 0000000000000000 0000000000000000-0000000000000000 0000000000000000 0-0, client: 80.11.52.189, server: media.uk.cloudy.fr, request: "GET /gridfs/4d4d526dea26b05041000016 HTTP/1.1", host: "media.foo.com"
2011/02/05 15:28:52 [alert] 7112#0: *2 zero size buf in writer t:0 r:0 f:0 0000000000000000 0000000000000000-0000000000000000 0000000000000000 0-0, client: 80.11.52.189, server: media.uk.cloudy.fr, request: "GET /gridfs/4d4d526dea26b05041000016 HTTP/1.1", host: "media.foo.com"

Any suggestion is welcome :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

饭团 2024-10-22 18:53:03

实际上,我破解了 gridFS 模块来访问 mongo 中的其他内容。然后我的同事提交了一个拉取请求,我认为这是最后完成的事情。如果您需要补丁,我也发现其中存在内存泄漏。该模块自 7 月份以来就没有开发过。可能是与新的 nginx 不兼容。我们大量使用它,因此如果我发现它与 .8x/Mongo 1.7.5 不兼容,我会修复它并通知您。同时我会询问 github 上的维护者。

此外,这不是由 10gen 开发的,因此您可能无法获得有关 mongodb-user 的帮助。这不是 Mongo 的错误。自 7 月以来 Mongo 发生了很大变化,因此这也可能是一个问题。 nginx 插件也依赖于 mongo C 驱动程序,该驱动程序可能已过时。我们在 nginx/0.7.67 和 mongo 1.6.5 上成功使用它。

使用 verbose (-vvv) 运行 mongo,跟踪 mongo 日志并点击它。查看您的请求是否实际上是在进行 mongo 查询以及是否存在错误

I actually hacked the gridFS module to access something else in mongo. My coworker submitted a pull request then, and I think that is the last thing that was done. I found a memory leak in it too if you would like the patch. This module has not been developed since July. It could be that it may not be compatible with new nginx. We are using this heavily so if I find it is not compatible with .8x/Mongo 1.7.5 I will fix it and let you know. I would ask the maintainer on github in the meantime.

Also this is not developed by 10gen, so you may not be able to get help on mongodb-user. It is not a bug with Mongo. Mongo has changed a lot since July so that may be a problem too. The nginx plugin relies on the mongo C driver too which may be out of date. We are using it successfully with nginx/0.7.67 and mongo 1.6.5.

Run your mongo with verbose (-vvv) and tail the mongo log and hit it. See if your request is actually making a mongo query and if there are errors with that

疧_╮線 2024-10-22 18:53:03

好吧,我找到了问题的根源,

我的文件是空的。
使用 mongoengine python GridFsProxy read() 给了我 0 但我仍然可以在 mongoterm、db.fs.files 集合中看到它们,其大小不同于 0 :/

我查看了在测试代码中添加文件的位置,这就是我的内容发现:

f1 =  open(path.join(PROJECT_ROOT,'test_files/marmot.jpg'), 'r')
f2 =  open(path.join(PROJECT_ROOT,'test_files/img-sanctuaire.png'), 'r')

files = [f1, f2]

# add logs 
for i in range(0, num):

    log = Foo.create(
         ...
        files=files,
     )
    # appends
    batch_insert_logs.append(log.to_mongo())

db = _get_db()
# Batch insert logs 
if batch_insert_logs:
    db.mycollection.insert(batch_insert_logs)

第一个日志图像有效,但所有其他日志图像为空,导致前面提到的错误。
将文件实例化位置更改为:

# add logs 
for i in range(0, num):
    f1 =  open(path.join(PROJECT_ROOT,'test_files/marmot.jpg'), 'r')
    f2 =  open(path.join(PROJECT_ROOT,'test_files/img-sanctuaire.png'), 'r')

    files = [f1, f2]

    log = Foo.create(
         ...
        files=files,
     )
    # appends
    batch_insert_logs.append(log.to_mongo())

db = _get_db()
# Batch insert logs 
if batch_insert_logs:
    db.mycollection.insert(batch_insert_logs)

完全解决了问题。

结论是mongoengine中可能某个地方有问题。
我将在 mongo 上尝试详细(-vvv)以查明问题。

Ok I found the root of the problem,

My files were empty.
Using mongoengine python GridFsProxy read() gives me 0 but I could still see them in the mongoterm, db.fs.files collection with a size different than 0 :/

I looked where I was adding files in my test code and here is what I found:

f1 =  open(path.join(PROJECT_ROOT,'test_files/marmot.jpg'), 'r')
f2 =  open(path.join(PROJECT_ROOT,'test_files/img-sanctuaire.png'), 'r')

files = [f1, f2]

# add logs 
for i in range(0, num):

    log = Foo.create(
         ...
        files=files,
     )
    # appends
    batch_insert_logs.append(log.to_mongo())

db = _get_db()
# Batch insert logs 
if batch_insert_logs:
    db.mycollection.insert(batch_insert_logs)

First log images were valid but all the others where empty resulting in the bug mentioned earlier.
Changing the files instantiation position to:

# add logs 
for i in range(0, num):
    f1 =  open(path.join(PROJECT_ROOT,'test_files/marmot.jpg'), 'r')
    f2 =  open(path.join(PROJECT_ROOT,'test_files/img-sanctuaire.png'), 'r')

    files = [f1, f2]

    log = Foo.create(
         ...
        files=files,
     )
    # appends
    batch_insert_logs.append(log.to_mongo())

db = _get_db()
# Batch insert logs 
if batch_insert_logs:
    db.mycollection.insert(batch_insert_logs)

Solved the problem completely.

The conclusion is that there is a problem somewhere probably in mongoengine.
I will try verbose (-vvv) on mongo in order to pinpoint the problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文