apache 增加新模块


1. 在线安装


sudo apt-get install apache2

sudo apt-get install apache2-dev



2. 编译安装模块


mod_helloworld.c

#include <httpd.h>
#include <http_protocol.h>
#include <http_config.h>

static int helloworld_handler(request_rec* r)
{
	
	if(!r->handler || strcmp(r->handler, "helloworld"))
	{
		return DECLINED;
		
	}
	 
	if(r->method_number != M_GET)
	{
		return HTTP_METHOD_NOT_ALLOWED;
		
	}
	
	ap_set_content_type(r, "text/html;charset=utf-8");
	ap_rputs("<!DOCTYPE>\n", r);
	ap_rputs("<html><body>\"hellworld\"<body/></html>", r);
	return OK;
}

static void helloworld_hooks(apr_pool_t* pool)
{
	ap_hook_handler(helloworld_handler, NULL, NULL, APR_HOOK_MIDDLE);
	
} 

module AP_MODULE_DECLARE_DATA helloworld_module = {
	
	STANDARD20_MODULE_STUFF,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	helloworld_hooks
};

(1) 编译

apxs -c mod_helloworld.c


(2) 安装


apxs -i mod_helloworld.la


(3) 查看模块

ls /usr/lib/apache2/modules/




(4) 修改配置加载模块


打开配置,加入如下配置

vi /etc/apache2/apache2.conf


LoadModule helloworld_module   /usr/lib/apache2/modules/mod_helloworld.so


<Location /helloworld>
    setHandler helloworld
</Location>



(5) 重启

sudo service apache2 restart


(6) 测试

浏览器打开

http://192.168.233.130/helloworld














  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值