设为首页 加入收藏

TOP

Nginx学习——http配置项解析编程(二)
2014-11-23 22:10:11 来源: 作者: 【 】 浏览:37
Tags:Nginx 学习 http 配置 解析 编程
rn rc;
}


ngx_http_mytest_conf_t* my_conf;
my_conf = ngx_http_get_module_loc_conf(r, ngx_http_mytest_module);


ngx_str_t type = ngx_string("text/plain");


u_char nginx_str_mytest[1024] = {0};
ngx_sprintf(nginx_str_mytest,"test_str=%s,test_flag=%i,test_num=%i,mytest_str=%s,mytest_num=%i",my_conf->my_str.data,my_conf->my_flag,my_conf->my_num,my_conf->mytest_str.data,my_conf->mytest_num);


r->headers_out.status = NGX_HTTP_OK;
r->headers_out.content_length_n = ngx_strlen(nginx_str_mytest);
r->headers_out.content_type = type;


rc = ngx_http_send_header(r);
if(rc == NGX_ERROR || rc>NGX_OK || r->header_only)
{
return rc;
}


ngx_buf_t* b;
b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
if(b == NULL)
{
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
b->pos = nginx_str_mytest;
b->last = nginx_str_mytest + ngx_strlen(nginx_str_mytest);
b->memory = 1;
b->last_buf = 1;


ngx_chain_t out;
out.buf = b;
out.next = NULL;


return ngx_http_output_filter(r, &out);
}


static void* ngx_http_mytest_create_loc_conf(ngx_conf_t* cf)
{
ngx_http_mytest_conf_t* conf;
conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_mytest_conf_t));
if(NULL == conf){
return NGX_CONF_ERROR;
}


conf->my_str.len = 0;
conf->my_str.data = NULL;
conf->my_num = NGX_CONF_UNSET;
conf->my_flag = NGX_CONF_UNSET;
return conf;
}


static char* ngx_http_mytest_merge_loc_conf(ngx_conf_t* cf, void* parent, void* child)
{
ngx_http_mytest_conf_t* prev = parent;
ngx_http_mytest_conf_t* conf = child;
ngx_conf_merge_str_value(conf->my_str, prev->my_str,"");


return NGX_CONF_OK;
}


在ngx.conf中http下面默认server中加入如下配置项


location /test{


test_flag on;


test_str "helloworld";


test_num 88;


mytest"hello" 88;


}


启动nginx


./configure --add-module=/home/chen123/nginx/exp3


make


make install


sudo /usr/local/nginx/sbin/nginx


结果如下


Nginx学习——http配置项解析编程


首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Java运用JNI调用dll实现屏蔽系统.. 下一篇AngularJS 的 IE 兼容性

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: