A.客戶端發送mand_t *cmd,void * conf);
/*命令*/
靜態ngx_command_t ngx_mands[] = {
{ ngx_string("hello_world "),
NGX _ HTTP _ LOC _ CONF | NGX _ CONF _ NOARGS,
ngx _命令
};
static u _ char ngx _ hello _ world[]= " hello world ";
靜態ngx_mands,/*模塊指令*/
NGX_HTTP_MODULE,/*模塊類型*/
NULL,/* init master */
空,/*初始化模塊*/
NULL,/*初始化進程*/
空,/*初始化線程*/
NULL,/*退出線程*/
NULL,/*退出進程*/
NULL,/*退出主機*/
NGX _模塊_ v 1 _填充
};
靜態ngx int t
ngx_mand_t *cmd,void *conf)
{
ngx_mand_t函數用於定義包含模塊指令的靜態數組ngx_mands。
& ltspan style = " font-size:16px;"& gt靜態ngx_command_t ngx_mands[] = {
{ngx_string("hello_world "),//設置指令名字符串,註意不能包含空格。稍後將詳細解釋數據類型ngx_str_t。
ngx _ http _ loc _ conf | ngx _ conf _ no args,//配置指令的合法位置,表示該位置部分合法,指令沒有參數。
ngx_mand_t *cmd,void *conf)
0,//後面的參數需要發現,我還沒用過。
0,
NULL },
ngx空命令
};& lt/span>。
b . static u _ charngx _ hello _ world[]=“hello world”是輸出到屏幕的字符串。
c.ngx_mands,/*模塊指令*/
NGX_HTTP_MODULE,/*模塊類型*/
NULL,/* init master */
空,/*初始化模塊*/
NULL,/*初始化進程*/
空,/*初始化線程*/
NULL,/*退出線程*/
NULL,/*退出進程*/
NULL,/*退出主機*/
NGX _模塊_ v 1 _填充
};& lt/span>。
它包含了模塊的主要內容和指令的執行部分,這將在下壹節詳細解釋。
E.處理程序ngx_http_hello_world_handler也是hello world模塊的核心部分。
& ltspan style = " font-size:16px;"& gt靜態ngx int t
ngx _ http _ hello _ world _ handler(ngx _ http _ request _ t * r)//ngx _ http _ request _ t * r可以訪問客戶端的頭和即將發送的回復的頭。
{
ngx _ int _ t rc
ngx _ buf _ t * b;
ngx _ chain _ t out
/* Http輸出緩沖*/
r-& gt;headers _ out . content _ type . len = sizeof(" text/plain ")-1;
r-& gt;headers _ out . content _ type . data =(u _ char *)" text/plain ";
b = ngx _ PC alloc(r-& gt;pool,sizeof(ngx _ buf _ t));
out . buf = b;
out.next = NULL
b-& gt;pos = ngx _ hello _ world
b-& gt;last = ngx _ hello _ world+sizeof(ngx _ hello _ world);
b-& gt;內存= 1;
b-& gt;last _ buf = 1;
r-& gt;headers _ out . status = NGX _ HTTP _ OK;
r-& gt;headers _ out . content _ length _ n = sizeof(ngx _ hello _ world);
ngx _ http _ send _ header(r);
return ngx _ http _ output _ filter(r & amp;out);
} & lt/span>。