Test,Nginx Hello World Module
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的更多相关文章
- Nginx - HTTP Configuration, Module Directives
Socket and Host Configuration This set of directives will allow you to configure your virtual hosts. ...
- Nginx - HTTP Configuration, Module Variables
The HTTP Core module introduces a large set of variables that you can use within the value of direct ...
- nginx install lua module
#install luajit #http://luajit.org/download.html .tar.gz cd LuaJIT- make install PREFIX=/home/allen. ...
- Nginx - Rewrite Module
Initially, the purpose of this module (as the name suggests) is to perform URL rewriting. This mecha ...
- 实战开发一个Nginx扩展 (Nginx Module)
repo地址 https://github.com/wujunze/nginx-http-echo-module nginx_module_echo 使用echo指令输出一个字符串 Nginx 版本 ...
- 编译nginx的源码安装subs_filter模块
使用nginx的反向代理功能搭建nuget镜像服务器时,需要针对官方nuget服务器的响应内容进行字符串替换,比如将www.nuget.org替换为镜像服务器的主机名,将https://替换为http ...
- 【原】Nginx添加Content-MD5头部压测分析
如需转载,必须注明原文地址,请尊重作者劳动成果. http://www.cnblogs.com/lyongerr/p/5048464.html 本文介绍了webbenck安装,但是最后使用的是ab工具 ...
- 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 ...
- Nginx - Configuration File Syntax
Configuration Directives The Nginx configuration file can be described as a list of directives organ ...
随机推荐
- spark-sql启动后在监控页面中显示的Application Name为SparkSQL::xxxx的疑问
启动spark-sql执行sql时,在监控页面中看到该Application的Name是SparkSQL:hadoop000(其中hadoop000是测试机器的hostname),就有个想法,修改下该 ...
- SQL必知必会笔记(1)
去SQL AXDB 中Query数据 Open the SQL > Connect > Select AXDB > new Query select REFID, ITEMID, R ...
- Jmeter命令行方式启动
在性能测试过程中,我们常常遇到这样的问题,使用Jmeter的GUI界面进行大并发量的性能测试时,界面容易卡死,无法继续进行性能测试.通过使用命令行方式启动jmeter是一个不错的方式.下面就简单介绍一 ...
- CODESOFT中的圆角矩形的弧度该怎样设置?
CODESOFT标签设计软件提供多种图形制作按钮,方便用户更为快捷的制作标签.其中就包括矩形,圆角矩形的快捷创建按钮.本文将介绍如何设置CODESOFT圆角矩形的弧度. 若有疑问可直接访问:htt ...
- Orchard官方文档翻译(七) 导航与菜单
原文地址:http://docs.orchardproject.net/Documentation/Navigation-and-menus 想要查看文档目录请用力点击这里 最近想要学习了解orcha ...
- 关于static/const的作用
这个简单的问题很少有人能回答完全.在C语言中,关键字static有三个明显的作用: 1)在函数体内,一个被声明为静态的变量在这一函数被调用过程中维持其值不变(该变量存放在静态变量区). 2) 在模块内 ...
- ASP.NET 数据库页面访问简单工具
在工作中,有很多项目已上线后,很多项目的数据库服务器都不会对外开放的,外网想直接访问客户数据库服务器时,可能会出现困难. 这时就需要一个可以查询,更新数据库操作的页面了: 本来用sql语句直接操作数据 ...
- List<string>里 每个元素重复了多少次
List<string>里 每个元素重复了多少次 static void Main(string[] args) { List<string> list = new List& ...
- 【EF 2】浅谈ADO数据模型生成串(二):数据库连接串分析
导读:上篇博客中介绍了ADO生成串的前一部分,本篇博客结合报错,接着介绍剩下的部分. 一.代码展示 <span style="font-family:KaiTi_GB2312;font ...
- keepalive实现web服务器active/passive
https://github.com/acassen/keepalived/blob/v1.2.13/doc/keepalived.conf.SYNOPSIS http://ngyuki.hatena ...