Tag Archives: module
实例:写Nginx module
对于一些访问量特别大,业务逻辑也相对简单的Web调用来说,通过一个nginx module来实现是一种比较好的优化方法。实现一个nginx module实际上比较简单。 1. nginx 配置添加 ./configure –add-module=/path/to/module1/source 2. 添加 /path/to/module1/source/config 文件,内容 ngx_addon_name=ngx_http_hello_module HTTP_MODULES=”$HTTP_MODULES ngx_http_hello_module” NGX_ADDON_SRCS=”$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_hello_module.c” CORE_LIBS=”$CORE_LIBS -lfoo” 最后一行如果没有使用其他library, 可以去掉 3. 源代码 /path/to/module1/source/ngx_http_hello_module.c, 主要的业务逻辑在make_http_get_body 中完善。典型的hello world源代码如下 #include <ngx_config.h> #include <ngx_core.h> #include <ngx_http.h> #define OUT_BUFSIZE 256 static char *ngx_http_hello_set(ngx_conf_t *cf, … Continue reading