ZBLOG

写一个nginx第三方模块,获取remote_addr这个变量的值

下面是一个简单的示例,展示如何编写一个nginx第三方模块来获取remote_addr这个变量的值:

”`c #include #include #include

static char *ngx_http_get_remote_addr(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); static ngx_int_t ngx_http_get_remote_addr_handler(ngx_http_request_t *r);

static ngx_command_t ngx_http_get_remote_addr_commands[] = {

{
    ngx_string("get_remote_addr"),
    NGX_HTTP_MAIN_CONF | NGX_HTTP_SRV_CONF | NGX_HTTP_LOC_CONF | NGX_HTTP_LIF_CONF | NGX_CONF_NOARGS,
    ngx_http_get_remote_addr,
    0,
    0,
    NULL
},
ngx_null_command

};

static ngx_http_module_t ngx_http_get_remote_addr_module_ctx = {

NULL,
NULL,

NULL,
NULL,

NULL,
NULL,

NULL,
NULL

};

ngx_module_t ngx_http_get_remote_addr_module = {

NGX_MODULE_V1,
&ngx_http_get_remote_addr_module_ctx,
ngx_http_get_remote_addr_commands,
NGX_HTTP_MODULE,

NULL,
NULL,
NULL,
NULL,

NULL,
NULL,

 	NULL,  
 	NULL,  

NGX_MODULE_V1_PADDING

};

static char *ngx_http_get_remote_addr(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) {

 	ngx_htt<br/><br/><br/><font size=1 color=#CCCCCC>内容由零声教学AI助手提供,问题来源于学员提问</font>

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=10201

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?