Nginx模块开发:自定义模块hello world

本文介绍了如何开发一个简单的Nginx自定义模块,通过配置nginx.conf并设置访问路径,当浏览器访问特定URL时,返回'just for fun!'的响应,展示自定义模块的基本使用。
摘要由CSDN通过智能技术生成
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>

static char *ngx_http_mytest(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static void *ngx_http_mytest_create_loc_conf(ngx_conf_t *cf);
static char *ngx_http_mytest_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child);


typedef struct {
	ngx_str_t str;
}ngx_http_mytest_loc_conf_t;

static ngx_command_t  ngx_http_mytest_commands[] = {
	{ 
		ngx_string("mytest"),
		NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
		ngx_http_mytest,
		NGX_HTTP_LOC_CONF_OFFSET,
		offsetof(ngx_http_mytest_loc_conf_t, str),
		NULL 
	},
	ngx_null_command
};

static ngx_http_module_t  ngx_http_mytest_module_ctx = {
	NULL,                                  
	NULL,                                 
	NULL,                               
	NULL,                                
	NULL,                                 
	NULL,                                 
	ngx_http_mytest_create_loc_conf, 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值