nginx模块开发


http://www.codinglabs.org/html/intro-of-nginx-module-development.html

http://www.nginx.com.cn/?cat=80
http://wiki.nginx.org/3rdPartyModules

PS http://0xc0dec.org/2010/11/23/nginx-directive-is-duplicate/
—————— 关于 设定配置文件为uint 的情况下,如果木有给定初始值NGX_CONF_UNSET_UINT,则会报错 描述符重复。

http://bollaxu.iteye.com/blog/855497
http://bollaxu.iteye.com/blog/900357

http://www.162cm.com/p/ngx_ext.html

打开调试,关闭daemon模式

~#vim nginx.conf

worker_processes  1;
daemon off; 
master_process  off;
error_log  /tmp/error.log debug;
pid /tmp/nginx_demo.pid;
events {
    worker_connections  1024;
}
http {
    include       /etc/nginx/mime.types;
    sendfile        on;
    keepalive_timeout  65;
    tcp_nodelay        on;
    server {
        listen   8100;
        server_name  localhost;
        access_log  /tmp/access.log;
        error_log  /tmp/error.log debug;
        location /hello {
            echo "Hi,this is a demo module";
        }
    }
}




http://code.google.com/p/emillers-guide-to-nginx-module-chn/wiki/NginxModuleDevGuide_CHN

http://www.evanmiller.org/nginx-modules-guide.html
http://www.evanmiller.org/nginx-modules-guide-advanced.html

http://www.pagefault.info/?p=251

http://lxr.evanmiller.org/http/source/core/ngx_core.h#L33

http://lxr.evanmiller.org/http/ident?i=NGX_OK


编译入C++模块包含其他lib的方案

http://blog.xiuwz.com/2011/11/27/nginx-build-with-cpp/

Nginx是基于C语言开发的,默认采用GCC编译。如果第三方模块需要采用C++来编写,需要如何做呢?网上不少教材采用修改Makefile或者在Confiugure中把GCC修改成G++,这种方案有一定的可行性,但很有可能导致一些其他的问题,比如说Nginx的off_t在32位系统的兼容性问题。另外这方法在nginx官方中也非常不推荐。

在Nginx代码中,本身有一段关于引入C++模块的实例代码 :/src/misc/ngx_cpp_test_module.cpp

extern "C" {
  #include <ngx_config.h>
  #include <ngx_core.h>
  #include <ngx_event.h>
  #include <ngx_event_connect.h>
  #include <ngx_event_pipe.h>
 
  #include <ngx_http.h>
 
  #include <ngx_mail.h>
  #include <ngx_mail_pop3_module.h>
  #include <ngx_mail_imap_module.h>
  #include <ngx_mail_smtp_module.h>
}

测试编译方法:./configure –with-ld-opt=”-lstdc++” –with-cpp_test_module && make

如果该C++模块还依赖了其他的C++库和头部文件,又该如何做呢?在网上没有找到类似的方法后,只能去看看nginx的configure和makefile的实现了。PS:nginx的makefile生成采用了自己的方式来做,对于源码中的Auto目录。(后续详细介绍)

通过分析,整理出nginx引入C++模块的几个步骤:

1、nginx头文件需要放在extern “c”中。如同ngx_cpp_test_module.cpp文件一样。

2、在模块中config文件中定义额外的头文件目录、第三方库。注意:NGX_ADDON_DEPS、NGX_ADDON_SRCS、CORE_INCS、CORE_LIBS几个定义。

ULIB="/path/to/lib/lib2-64"
CORE_INCS="$CORE_INCS $ULIB/ullib/include $ULIB/dict/include $ULIB/ccode/include $ULIB/cache/include $ULIB/xxx/output/include /usr/include/libxml2 /usr/include/pcre"
CORE_LIBS="$CORE_LIBS -lcrypto -lm -L$ULIB/ullib/lib/ -L$ULIB/ccode/lib/ -L$ULIB/htmlparser2/lib/ -L$ULIB/dict/lib/ -L$ULIB/cache/lib/ -L$ULIB/xxx/output/lib -lpolicy -lpcre -lulccode -lhtmlparser2 -luldict -lmcache -lxml2 -lcrypt -lcrypto -lullib"

3、在configure中添加“–with-ld-opt=”-lstdc++” ”

完成这几个步骤就done了。

-------------------------------------------------------------

Nginx模块参考手册中文版

http://www.howtocn.org/nginx:nginx%E6%A8%A1%E5%9D%97%E5%8F%82%E8%80%83%E6%89%8B%E5%86%8C%E4%B8%AD%E6%96%87%E7%89%88

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值