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














猜你喜欢

转载自blog.csdn.net/u011857683/article/details/80517023
今日推荐