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. Python面试里面的那些问题

    Q:Python里面的数据结构都有哪些? 答:str,list,tuple,set,frozenset,dict,以上是Python默认的数据结构,还有容器类型collections,其中包含:Cou ...

  2. Metrics.NET report to Zabbix

    废话不多说,先上git地址 https://github.com/binking338/Metrics.Reporters.ZabbixReporter 实现了Metrics.NET到Zabbix的报 ...

  3. Linux-wget/tar/ln 函数

    1. 获取软件包,可以使用wget的方式, ubuntu可以使用apt-get source来获取源代码 wget 是一个在网络上进行下载的简单而强大的自由软件,支持HTTP,HTTPS,FTP协议, ...

  4. 对.Net系统架构改造的一点经验和教训

    如果你对项目管理.系统架构有兴趣,请加微信订阅号"softjg",加入这个PM.架构师的大家庭 在互联网行业,基于Unix/Linux的网站系统架构毫无疑问是当今主流的架构解决方案 ...

  5. 【练习】手工生成awr报告

    ①首先进入$ORACLE_HOME/rdbms/admin目录 [oracle@host02 ~]$ cd $ORACLE_HOME/rdbms/admin 该目录下 [oracle@host02 a ...

  6. C# Exception 对象的属性

    关于 C# 中 Exception 对象的属性,在程序出现异常时,需要记录异常的信息,并把信息保存起来或输出,以方便准确定位异常的根源,以下是 Exception  对象的属性 名称          ...

  7. sqool导出oracle数据

    set colsep '|'               --设置|为列分隔符 set echo off --在用start命令执行一个sql脚本时,是否显示脚本中正在执行的SQL语句 set fee ...

  8. VC与JavaScript交互(三) --- CWebPage类调用javascript函数(给js函数传参,并取得返回值)

    ①需要一个别人写好的类CWebPage,将其对于的两个文件WebPage.h和WebPage.cpp添加到工程中. ②添加WebBrowser控件,在视图/对话框类的头文件中#include &quo ...

  9. 网络编码 GB2312、GBK与UTF-8的区别

    GB2312.GBK与UTF-8的区别  这是一个异常经典的问题,有无数的新手站长每天都在百度这个问题,而我,作为一个“伪老手”站长,在明白这个这个问题的基础上,有必要详细的解答一下.  首先,我们要 ...

  10. hbase基本结构

    HBASE  基本结构一.overview1. hbase <=> NOSQL     不错,hbase 就是某种类型的nosql 数据库,唯一的区别就是他支持海量的数据.    hbas ...