Nginx模組開發 研究1

2021-08-30 14:09:27 字數 4524 閱讀 5737

不同的模組流程不同這是乙個直接從從配置中讀取資訊,並返回給客戶端的例子。

#include

#include

#include

static char* ngx_echo_readconf(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);

static void* ngx_echo_create_loc_conf(ngx_conf_t *cf);

static char* ngx_echo_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child);

typedef struct ngx_echo_loc_conf_t;

// 讀取配置檔案內容 echo -> ecdata

// 1、ngx_echo_readconf是程式第一步

// 定義模組 ngx_http_hi_module 就是模組的名字

// 主要的功能在這裡

); // 這個和上面是對應的。

return ngx_http_output_filter(r, &out); // 交給過濾器

clcf->handler = ngx_echo_handler; // 2、ngx_echo_handler是程式第二步

ngx_conf_set_str_slot(cf,cmd,conf);

return ngx_conf_ok;

static void *

ngx_echo_create_loc_conf(ngx_conf_t *cf)

printf("called:ngx_echo_create_loc_conf\n");

ngx_echo_loc_conf_t  *conf;

conf = ngx_pcalloc(cf->pool, sizeof(ngx_echo_loc_conf_t));

if (conf == null) {

return ngx_conf_error;

conf->ecdata.len=0;

conf->ecdata.data=null;

conf->enable = ngx_conf_unset;

return conf;

static char *

ngx_echo_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)

printf("called:ngx_echo_merge_loc_conf\n");

ngx_echo_loc_conf_t *prev = parent;

ngx_echo_loc_conf_t *conf = child;

ngx_conf_merge_str_value(conf->ecdata, prev->ecdata, 10);

ngx_conf_merge_value(conf->enable, prev->enable, 0);

if(conf->enable)

ngx_echo_init(conf);

return ngx_conf_ok;

return ngx_conf_ok;

Nginx模組開發(1) 初探模組開發流程

一 準備工作 1 安裝pcre庫 cd usr local wget tar zxvf pcre 8.38.tar.gz cd pcre 8.38 configure make make install 2.安裝zlib cd usr local wget tar zxvf zlib 1.2.8.t...

python CSV模組 研究1

逗號分隔值 comma sparated value,csv 通常用在電子 與資料庫最常用的匯入和匯出格式。也是電子 軟體與純文字之間互動資料。實際上,csv都不算是乙個真正的結構化資料,csv檔案內容僅僅是一些用逗號分隔的原始字串值。csv模組以reader和writer物件來讀取和寫入序列。程式...

nginx的模組開發

nginx剛剛在國內開始流行的時候,我就把它引入公司技術體系,用來替代apache主要做動靜分離。nginx的併發處理能力和穩定性,以及優秀的軟體架構深深得吸引了我,讓我跨入了高效能伺服器開發的大門。正巧當時要基於flash技術開發一套 系統,而且要支援 環境,而當時並沒有什麼好的辦法讓flash通...