ngx_addon_name=ngx_http_mytest_module
HTTP_MODULES="$HTTP_MODULES ngx_http_mytest_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_mytest_module.c"

ngx_http_mytest_module.c

 #include <ngx_core.h>
#include <ngx_http.h>
#include <nginx.h> static char *ngx_http_mytest(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static ngx_int_t ngx_http_mytest_handler(ngx_http_request_t *r); static ngx_command_t ngx_http_mytest_commands[] = {
{ngx_string("mytest"),
NGX_HTTP_MAIN_CONF | NGX_HTTP_SRV_CONF | NGX_HTTP_LOC_CONF | NGX_HTTP_LMT_CONF | NGX_CONF_NOARGS,
ngx_http_mytest,
NGX_HTTP_LOC_CONF_OFFSET,
,
NULL}, ngx_null_command
}; static ngx_http_module_t ngx_http_mytest_module_ctx = {
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
}; ngx_module_t ngx_http_mytest_module = {
NGX_MODULE_V1,
&ngx_http_mytest_module_ctx,
ngx_http_mytest_commands,
NGX_HTTP_MODULE,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NGX_MODULE_V1_PADDING
}; static char *ngx_http_mytest(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_mytest_handler; return NGX_CONF_OK;
} static ngx_int_t ngx_http_mytest_handler(ngx_http_request_t *r)
{
if(!(r->method & NGX_HTTP_GET))
return NGX_HTTP_NOT_ALLOWED; ngx_int_t rc = ngx_http_discard_request_body(r);
if(rc != NGX_OK)
return rc; ngx_str_t type = ngx_string("text/plain");
ngx_str_t response = ngx_string("Hello World!");
r->headers_out.status = NGX_HTTP_OK;
r->headers_out.content_length_n = response.len;
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_create_temp_buf(r->pool, response.len);
if(b == NULL)
return NGX_HTTP_INTERNAL_SERVER_ERROR; ngx_memcpy(b->pos, response.data, response.len);
b->last = b->pos + response.len;
b->last_buf = ; ngx_chain_t out;
out.buf = b;
out.next = NULL; return ngx_http_output_filter(r, &out);
}

./configure --add-module=

Test,Nginx Hello World Module的更多相关文章

  1. Nginx - HTTP Configuration, Module Directives

    Socket and Host Configuration This set of directives will allow you to configure your virtual hosts. ...

  2. Nginx - HTTP Configuration, Module Variables

    The HTTP Core module introduces a large set of variables that you can use within the value of direct ...

  3. nginx install lua module

    #install luajit #http://luajit.org/download.html .tar.gz cd LuaJIT- make install PREFIX=/home/allen. ...

  4. Nginx - Rewrite Module

    Initially, the purpose of this module (as the name suggests) is to perform URL rewriting. This mecha ...

  5. 实战开发一个Nginx扩展 (Nginx Module)

    repo地址 https://github.com/wujunze/nginx-http-echo-module nginx_module_echo 使用echo指令输出一个字符串 Nginx 版本 ...

  6. 编译nginx的源码安装subs_filter模块

    使用nginx的反向代理功能搭建nuget镜像服务器时,需要针对官方nuget服务器的响应内容进行字符串替换,比如将www.nuget.org替换为镜像服务器的主机名,将https://替换为http ...

  7. 【原】Nginx添加Content-MD5头部压测分析

    如需转载,必须注明原文地址,请尊重作者劳动成果. http://www.cnblogs.com/lyongerr/p/5048464.html 本文介绍了webbenck安装,但是最后使用的是ab工具 ...

  8. How to Install and Configure Nginx from Source on centos--转

    1.CentOS - Installing Nginx from source http://articles.slicehost.com/2009/2/2/centos-installing-ngi ...

  9. Nginx - Configuration File Syntax

    Configuration Directives The Nginx configuration file can be described as a list of directives organ ...

随机推荐

  1. 《Code Complete》ch.21 协同构建

    WHAT? 所有的协同构建技术都试图通过这样那样的途径,将展示工作的过程正式化,以便将错误暴露出来 WHY? 提高缺陷检出率,从而缩短开发周期,降低开发成本 发现不明显的错误信息,如不恰当的注释.硬编 ...

  2. H264的句法和语法总结(一)分层结构

    在H.264 中,句法元素共被组织成  序列.图像.片.宏块.子宏块五个层次.在这样的结构中,每一层的头部和它的数据部分形成管理与被管理的强依赖关系,头部的句法元素是该层数据的核心,而一旦头部丢失,数 ...

  3. Grunt 之 使用 JavaScript 语法检查工具 jshint

    前端开发环境准备好了,我们准备开始进行开发. 前端开发的主力语言是 JavaScript,这是一种脚本语言,没有编译器,也就没有了编译器带给我们的语法检查,怎样保证代码的质量呢?jshint 是一个强 ...

  4. 在 WPF 程序中使用 MVVM 模式

    MVVM 模式是一个很久之前的技术了,最近因为一个项目的原因,需要使用 WPF 技术,所以,重新翻出来从前的一段程序,重温一下当年的技术. MVVM 模式 MVVM 实际上涉及三个部分,Model, ...

  5. Django中级篇(上)

    Form验证 django中的Form一般有两种功能: 输入html-----------不能你自己写一些标签,而帮你自动生成 验证用户输入-------将用户验证信息保存起来,可以传到前段 #!/u ...

  6. java服务器

    WebLogic BEA公司开发的(被Oracle收购了)收费的 支持JavaEE所有的规范(ejb servlet/jsp规范) java  mysql(oracle)      2.WebSphe ...

  7. 跨域请求之JSONP 三

    script请求返回JSON实际上是脚本注入.它虽然解决了跨域问题,但它不是万能的. 不能接受HTTP状态码 不能使用POST提交(默认GET) 不能发送和接受HTTP头 不能设置同步调用(默认异步) ...

  8. WP8——页面跳转方法

      1.页面传值: this.NavigationService.Navigate(new Uri("/SecondPage.xaml?CustomerId=1234&Product ...

  9. .NET 命名规范 代码示例

    class Person { /// <summary> /// 公有字段.属性 首字母大写 /// </summary> public string FirstName; p ...

  10. poj3122 pie

    方法:二分. 题目意思:要过生日了,我请大家吃pie,然后人数一共是f+1(我自己).每个人的pie不能是拼接的,而且每个人的面积是一样的,这样就用二分枚举. 范围是0-最大的那块pie. 然后用每一 ...