nginx模块开发

news/2024/7/10 22:17:56 标签: nginx, 2010

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


http://www.niftyadmin.cn/n/1858864.html

相关文章

7.4选择类排序

7.4选择类排序 算法思想&#xff1a;每一趟(例如第i趟&#xff09;在后面n-i2(i1,2,3,…,n-1)个待排序的元素中选取关键字最小的元素&#xff0c;作为有序子序列的第i个元素&#xff0c;直到第n-1趟做完&#xff0c;待排序的元素只剩一个&#xff0c;就不用再选了。 包括简单…

别再抱怨复杂的垃圾分类了,全国 53 个沿海城市,可能都要面临这个问题

原创&#xff1a;HyperAI超神经 关键词&#xff1a;海洋塑料垃圾 机器学习 图像识别 人类产生的废弃物有意无意地漂进大海&#xff0c;而这些废弃物中&#xff0c;许多类型的塑料无法分解&#xff0c;严重威胁着鱼类、海鸟、海洋爬行动物、海洋哺乳动物&#xff0c;以及船只和沿…

regexec

http://pubs.opengroup.org/onlinepubs/009695399/functions/regcomp.htmlhttp://linux.die.net/man/3/regexecPS 以上两个链接才是王道&#xff0c;国内的资料&#xff0c;包括本文最后保存的链接同样是错误的。Name regcomp, regexec, regerror, regfree - POSIX regex func…

R ARIMA 时间序列预测

An R Time Series Tutorial http://www.stat.pitt.edu/stoffer/tsa2/R_time_series_quick_fix.htm http://www.stat.pitt.edu/stoffer/tsa2/Examples.htmhttp://stat.ethz.ch/R-manual/R-patched/library/stats/html/predict.arima.html相关toolkits http://gretl.sourceforg…

用算法远离食物中毒,让这个夏天更安心

By 超神经场景描述&#xff1a;夏天里&#xff0c;经常有食物中毒的事件发生&#xff0c;严重的还会对生命造成威胁。对于餐厅的食品安全问题&#xff0c;有一些研究者们&#xff0c;动用自然语言处理、计算机视觉等机器学习技术&#xff0c;帮助卫生部门发现潜在的食品安全隐患…

隐马尔可夫(HMM)模型

http://www.52nlp.cn/hmm-learn-best-practices-one-introduction 隐马尔可夫(HMM)模型的各种语言实现 http://sjtutmz.blog.163.com/blog/static/988886602011863723740/隐马尔科夫模型HMM自学http://hi.baidu.com/soulingm/blog/item/51345bd9820a73d5b7fd48a6.html

unicode编码和中国的相互转换

如果你的原始文件1.properties&#xff08;该文件的编码中国&#xff09;。要转换unicode的 在cmd通过进入你在哪里在这种类型的文件夹&#xff1a; native2ascii -encoding gb2312 1.properties 2.properties&#xff0c; 运行命令后你会在当前文件夹下看到一个2.properties的…

7.5归并排序

7.5归并排序 假定待排序表含有n个记录&#xff0c;则可以看成n个有序的子表&#xff0c;每个子表长度为1&#xff0c;然后两两归并&#xff0c;得到[n/2]个长度为2或者1的有序表&#xff1b;再两两归并&#xff0c;……如此重复&#xff0c;直到合并成一个长度为n的有序表为止…