(一)安装nginx前的准备

安装nginx需要安装openssl和pcre,具体安装步骤请参考nginx安装的相关博文

(二)nginx和nginx-gridfs 联合编译安装

nginx-gridfs 源码下载(包含Mongo-C-Driver可用的下载链接):地址 http://files.cnblogs.com/de0319gh/nginx-gridfs.zip

nginx和nginx-gridfs 联合编译安装三个步骤:

(1)./configure --prefix=/usr/local/nginx --with-openssl=/usr/include/openssl --with-http_stub_status_module --add-module=/home/cdh/Downloads/mdirolf-nginx-gridfs

(2)make        (3)make install

(三)nginx-gridfs 配置

配置的语法说明:

gridfs db_name [root_collection] [field] [type] [user] [pass];

mongo mongodb url;

[root_collection]: 选择collection,如root_collection=blog, mongod就会去找blog.files与blog.chunks两个块,默认是fs

[field]:查询字段,保证mongdb里有这个字段名,支持_id, filename, 可省略, 默认是_id

[type]:解释field的数据类型,支持objectid, int, string, 可省略, 默认是int

[user]:用户名, 可省略

[pass]:密码, 可省略

配置示例:

(1)指定db为my_app,其他均为默认,默认服务器为本地

location /gridfs/ { gridfs my_app; }

(2)

location /gridfs/ {
gridfs my_app field=filename type=string;
mongo 127.0.0.1:;
}

(3)用于副本集

location /gridfs/ {
gridfs my_app field=filename type=string;
mongo "foo"
10.7.2.27:
10.7.2.28:;
}

(4)完整配置

location /gridfs/ {
gridfs my_app
root_collection=pics
field=_id
type=int
user=foo
pass=bar;
mongo 127.0.0.1:;
}

(四)注意点

(1)在测试配置时要记住不要将nginx的文件过期缓存时间配置开启了,最好是在配置好服务器以后再做这个工作,否则很容易造成配置错误的假象。

(2)要保证系统启动过程中,MongoDB比nginx先启动,否则nginx-gridfs初始化的时候不能正确链接MOngoDB数据库。

了解CentOS守护进程启动顺序的可以参考 http://wenku.baidu.com/view/f13befcfa1c7aa00b52acb40.html

查看启动顺序 ls /etc/rc3.d

以上内容都时链接到/etc/init.d/目录里的相应守护进程启动脚本,S55nginx 意思时nginx的守护进程启动顺序为55,S85mongod 意思时mongod的启动顺序为85,问题就在mongod比nginx晚启动。
                修改启动顺序,将mongod的启动顺序值改为比nginx小的数:
                mv /etc/rc3.d/S85mongod /etc/rc3.d/S54mongod
                mv /etc/rc5/d/S85mongod /etc/rc5.d/S54mongod
                ok,现在reboot重启解决问题。

(五)nginx-gridfs错误解决

问题描述:

nginx -V检查毫无问题,但是访问所有gridfs内容均报503 Service Temporarily Unavailable,看nginx日志:Mongo connection dropped, could not reconnect。

解决方案:重新clone gridfs,然后不要git submodule init; git submodule update; 而是:

git clone https://github.com/eagleas/mongo-c-driver.git

换了一个别人的mongo-c-driver,重新编译安装nginx即可。

文章出处:https://github.com/mdirolf/nginx-gridfs/issues/52

引用:

To fix the isseu you need the latest master branch of the C driver (the GridFS module uses another branch, which seems to be faulty).

After cloning this repo, do not do 'git submodule init && git subodule update', but instead:
    
git clone https://github.com/eagleas/mongo-c-driver.git

Then compile nginx as usual.

There are one problem is that you must delete the -Werror option of gcc in [nginx-source/objs/MakeFile].
     
If you don't do that, the warning will be treated as errors when you do make.

the log of make below:

cc1: warnings being treated as errors
             /home/Administrator/upload/nginx-gridfs//mongo-c-driver/src/numbers.c
            
gcc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter
-Wunused-function -Wunused-variable -Wunused-value -Werror -g --std=c99
-Isrc -I src/core -I src/event -I src/event/modules -I src/os/unix -I
objs  \  -o objs/ngx_modules.o \

关于nginx的卸载

nginx的卸载要看你是怎么装的nginx。RPM装的 用rpm -e卸载
      yum装的用 yum remove卸载 ,源码装的直接删文件就OK.

另外一篇比较好的介绍mongo+nginx-gridfs安装的地址 http://blog.sina.com.cn/s/blog_40e8378d0100oxuy.html

nginx-gridfs 的安装配置和使用的更多相关文章

  1. nginx,php-fpm的安装配置

    在centos7.2的系统下安装nginx和php-fpm nginx 安装 yum install -y nginx 即可完成安装 配置 由于之前项目使用的是apache,所以项目目录在var/ww ...

  2. Nginx概述及安装配置

    1.概述 Nginx是一款开源的,高性能的Http和反向代理服务器,同时也是一个IMAP.POP3.SMTP代理服务器:Nginx可以作为一个HTTP服务器进行网站的发布处理,也可以作为反向代理进行负 ...

  3. CentOS7下搭建Nginx+PHP7的安装配置

    一.安装编译工具及库文件: yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel 环境要求 nginx是C ...

  4. nginx+php windows安装配置

    https://blog.csdn.net/zjiang1994/article/details/72876193 https://blog.csdn.net/bruce_wang_janet/art ...

  5. Nginx的基本安装配置

    Centos7安装nginx 升级nginx 升级可能遇到问题(我没有遇到, 参考的另一篇文章描述的) 检查nginx版本, 确认安装成功 nginx配置文件 虚拟主机配置 配置文件中可以用的全局变量 ...

  6. Nginx源码安装配置

    Nginx web服务器简介 Nginx ("engine x") 是一个高性能HTTP 和 反向代理 服务器.IMAP.POP3.SMTP 服务器. Nginx 是由 Igor ...

  7. nginx 源码安装配置详解(./configure)

    在"./configure"配置中,"--with"表示启用模块,也就是说这些模块在编译时不会自动构建,"--without"表示禁用模块, ...

  8. thinkphp nginx+phpcgj安装配置

    环境:mysql-5.6.26             nginx-1.9.4.tar.gz   php-5.6.13 程序框架ThinkPHP 客户要求必须使用nginx + php 1.首先安装n ...

  9. Linux系统下Nginx+PHP 环境安装配置

    一.编译安装Nginx 官网:http://wiki.nginx.org/Install 下载:http://nginx.org/en/download.html # tar -zvxf nginx- ...

  10. [Nginx]Ubuntu18.04 安装配置Nginx1.13.6+FastDFS

    一. 安装fastdfs依赖包 1. 解压缩libfastcommon-master.zip 2. 进入到libfastcommon-master的目录中 3. 执行 ./make.sh 4. 执行 ...

随机推荐

  1. mysql各种日志对应的配置项

    01.error_log --log-error=<file_name> 02.general_log --general-log-file=<file_name> --gen ...

  2. Qt creator error: LNK1123: 转换到 COFF 期间失败: 文件无效或损坏(vs2010的嵌入式清单文件)

    下面是vs2010导入别人文件时出现的问题的解决方案:VS2010在经历一些更新后,建立Win32 Console Project时会出“error LNK1123” 错误,解决方案为将 项目|项目属 ...

  3. QT父子与QT对象delete

    原地址:http://www.qteverywhere.com/archives/437 很多C/C++初学者常犯的一个错误就是,使用malloc.new分配了一块内存却忘记释放,导致内存泄漏.Qt的 ...

  4. Go语言语法汇总

    最近看了看GoLang,把Go语言的语法总结了一下,做个快速参考 数据类型 var varName type,var var1,var2… type,var varName type = Value, ...

  5. JTextPane 的 undo 、 redo

    实现文本框输入内容的单条记录撤销,重做,通过按钮实现 以及通过JList的多条撤销.重做操作(类似PS) 昨天还在为自己写不出代码怎么办而伤心,没想到今天上午就实现了,并且还完善了功能: 可以在撤销一 ...

  6. 【Leetcode】二叉树简单路径最大和问题

    问题一:二叉树任意两个叶子间简单路径最大和 示例: -100 /   \ 2   100 /  \ 10   20 思路:这个问题适用于递归思路. 首先,将问题简单化:假设包含最大和summax的简单 ...

  7. Appium Android Bootstrap控制源代码的分析AndroidElement

    通过上一篇文章中<Appium Android Bootstrap源代码分析之简单介绍>我们对bootstrap的定义以及其在appium和uiautomator处于一个什么样的位置有了一 ...

  8. 优先队列(priorityqueue)

    队列是先进先出的线性表,顾名思义,优先队列则是元素有优先级的队列,出列的顺序由元素的优先级决定.从优先队列中删除元素是根据优先权的高低次序,而不是元素进入队列的次序.优先队列的典型应用是机器调度等. ...

  9. 实现DataGridView和DevExpress.GridControl表头全选功能

    1)DevExpress控件的GridView的实现多选操作 先讲DevExpress控件的GridView的实现,要实现的功能基本上是处理单击全选操作.重新绘制表头等操作,首先在加载第一步实现相关的 ...

  10. T-SQL事务

    事务 订火车票的时候,下一个订单,这个订单中,包含多个购买信息,要么全部执行,要么全部不执行,合作事务就是来处理这种模型的一种机制. --关键字:transaction 或 tran 简写形式 --开 ...