nginx handler ngx_http_core_module
来源:互联网 发布:手机淘宝秒杀怎么刷新 编辑:程序博客网 时间:2024/06/07 06:10
Nginx 按location配置的加载做法。
ngx_http_test_module.c
/***/#include <ngx_core.h>#include <ngx_http.h>#include <ngx_config.h>static ngx_str_t data = ngx_string("nginx.\n");static char *ngx_http_test_init(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);static ngx_int_t ngx_http_test_handler(ngx_http_request_t *r);static ngx_command_t ngx_http_test_commands[] = { { ngx_string("test"), NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS, ngx_http_test_init, NGX_HTTP_LOC_CONF_OFFSET, 0, NULL}, ngx_null_command};static ngx_http_module_t ngx_http_test_ctx = { NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};ngx_module_t ngx_http_test_module = { NGX_MODULE_V1,&ngx_http_test_ctx,ngx_http_test_commands,NGX_HTTP_MODULE,NULL, /* init master */ NULL, /* init module */NULL, /* init process */NULL, /* init thread */ NULL, /* exit thread */ NULL, /* exit process */NULL, /* exit master */ NGX_MODULE_V1_PADDING};static char *ngx_http_test_init(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_core_loc_conf_t *clcf;clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);clcf->handler = ngx_http_test_handler;/* *ngx_conf_set_str_slot(cf,cmd,conf); */return NGX_CONF_OK;}static ngx_int_tngx_http_test_handler(ngx_http_request_t *r) { ngx_buf_t *b; ngx_int_t rc; ngx_chain_t out;if (r->method & NGX_HTTP_POST) { return NGX_HTTP_NOT_ALLOWED;}rc = ngx_http_discard_request_body(r);if (NGX_OK != rc) { return rc;}r->headers_out.status = NGX_HTTP_OK;r->headers_out.content_length_n = data.len;r->headers_out.content_type.data = (u_char *) "text/html";r->headers_out.content_type.len = sizeof("text/html") - 1;if (r->method & NGX_HTTP_HEAD) { rc = ngx_http_send_header(r);if (NGX_OK != rc) { return rc;}}b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));if (NULL == b) { return NGX_HTTP_INTERNAL_SERVER_ERROR;}b->pos = data.data;b->last = data.data + data.len;b->last_buf = 1;b->memory = 1;out.buf = b;out.next = NULL;rc = ngx_http_send_header(r);if (NGX_OK != rc) { return rc;}return ngx_http_output_filter(r, &out);}
conf
ngx_addon_name=ngx_http_test_moduleHTTP_AUX_FILTER_MODULES="$HTTP_AUX_FILTER_MODULES ngx_http_test_module"NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_test_module.c"
指令里用的是NGX_CONF_NOARGS,所以location为
location /test/ {test;}
0 0
- nginx handler ngx_http_core_module
- Nginx 的ngx_http_core_module模块
- nginx ngx_http_core_module location指令详解
- Nginx配置详情-配置说明-参数优化-ngx_http_core_module模块变量(三)
- nginx handler模块
- 十七.HTTP核心模块(ngx_http_core_module)
- ngx_http_core_module模块提供的变量
- [nginx源码分析]nginx handler 模块解析
- Nginx handler 返回值解释
- nginx通过ngx_array_push()获取handler
- nginx phase handler的原理和选择
- nginx phase handler的原理和选择
- nginx模块开发之handler函数
- nginx处理post请求的handler
- nginx源码分析(8)——phase handler处理
- nginx开发学习——handler模块(一)
- nginx开发学习——handler模块(二)
- Nginx开发从入门到精通(二):handler模块
- 访问者模式(Visitor)
- 【Java常用类库】_比较器(Comparable、Comparator)笔记
- 【Java常用类库】_观察者设计模式笔记
- 【Java常用类库】_正则表达式笔记
- 【Java常用类库】_定时调度笔记
- nginx handler ngx_http_core_module
- 【JAVA IO】_File类笔记
- 【JAVA IO】_RandomAccessFile笔记
- 【JAVA IO】_字节流与字符流笔记
- 套接字选项的应用
- platform设备和驱动的注册(3)
- 【JAVA IO】_字节-字符转换流笔记
- 用GDB调试程序(一)
- MySQL数据库InnoDB和MyISAM数据引擎的差别