• nginx+gridfs+mongodb 配置访问png图片显示无法加载问题


    第一种情况:

    上传文件后,浏览器中请求:http://&lt;nginx server ip>:<port>/gfs/<my file> 浏览器出现“无法打开页面”的错误,查看错误日志,http error code 500。error.log中显示:
    malloc(18446744056529682432) failed (12: Cannot allocate memory), client: <Client IP>, server: localhost, request: "GET /gfs/test2.zip HTTP/1.1", host: "<Nginx server IP>"

    但是查看访问请求是成功的 get请求返回200,怎么也想不通,想着nginx配置文件也没问题呀,mongo数据库也能看到图片

    于是又捋了下流程,首先用的是nginx1.47的版本,mongo-3.2版本

    还有mongo和nginx启动顺序也有先后的,先启动mongo后启动nginx,因为nginx在启动的时候要找mongo,也按照这种方法做了,还是报无法加载图片

    于是各种百度,发现原来副本集配置需要在nginx中写上所有的主机地址

    nginx副本集的配置:
    location /static/ {
             gridfs ebook;
                    field=filename
                    type=string;
             mongo "foo"

                192.168.1.60:27017
                192.168.1.61:27017
                192.168.1.62:27017;

    }

    对,没错儿!  nginx中的副本集中就是这样写的。

    配置说明

    gridfs 表示告诉nginx服务器要调用gridfs模块

    root_collection= 指定Gridfs collection的前缀. 默认: fs

    field= 指定用于查询的字段 可以是 _id 和 filename. 默认: _id

    type= 指定查询的类型,这里支持 objectid, string 和int. 默认: objectid

    user= 指定数据库的用户名. 默认: NULL

    pass= 指定数据库的密码. 默认: NULL

     第二种情况:

    mongo所在的机器和nginx不在同一台机器上,但在同一内网中

    访问不到图片(访问超时)http://192.168.1.10/sxsdb/111.jpg

    查看nginx错误日志报连不上主节点,如果nginx配置没问题,那就是mongo副本的问题了

    2017/10/10 14:07:55 [error] 28124#0: Mongo Exception: Cannot connect to primary node.
    2017/10/10 14:07:55 [error] 28125#0: Mongo Exception: Cannot connect to primary node.
    2017/10/10 14:07:55 [alert] 27937#0: worker process 28124 exited with fatal code 2 and cannot be respawned
    2017/10/10 14:07:55 [alert] 27937#0: worker process 28125 exited with fatal code 2 and cannot be respawned

    在mongo副本中

    test:PRIMARY>rs.conf()  查看副本的配置信息

    {
    "_id" : "test",
    "version" : 3,
    "protocolVersion" : NumberLong(1),
    "members" : [
    {
    "_id" : 0,
    "host" : "127.0.0.1:17017",
    "arbiterOnly" : false,
    "buildIndexes" : true,
    "hidden" : false,
    "priority" : 1,
    "tags" : {

    },
    "slaveDelay" : NumberLong(0),
    "votes" : 1
    },
    {
    "_id" : 1,
    "host" : "127.0.0.1:27017",
    "arbiterOnly" : false,
    "buildIndexes" : true,
    "hidden" : false,
    "priority" : 1,
    "tags" : {

    },
    "slaveDelay" : NumberLong(0),
    "votes" : 1
    }
    ]

    这时看到的host为127.0.0.1 而nginx中配置的是内网地址,

    location /test/ {
       gridfs test 
      field=filename
    type=string;
    mongo "test"
    172.17.1.111:17017
    172.17.1.111:27017;
    }

     接着修改mongo副本中127.0.0.1为内网地址

    test:PRIMARY> cfg=rs.conf()

    test:PRIMARY>cfg.members[0].host = "172.17.1.111:17017"

    test:PRIMARY>cfg.members[1].host = "172.17.1.111:27017"

    修改后测试ok

     

  • 相关阅读:
    hdu 3371 Connect the Cities
    hust 1102 Constructing Roads
    hdu 1856 More is better
    hdu 1325 Is It A Tree?
    poj 2828 Buy Tickets (线段树)
    sdut 2351 In Danger (找规律)
    poj 2528 Mayor's posters(线段树)
    poj 2352 Stars (树状数组)
    poj 2492 A Bug's Life (并查集)
    poj 1703 Find them, Catch them(并查集)
  • 原文地址:https://www.cnblogs.com/rutor/p/6866270.html
Copyright © 2020-2023  润新知