C语言-apache mod(模块开发)-采用apxs开发实战(centos7.2 linux篇)





名词解释:apxs


apxs is a tool for building and installing extension modules for the Apache HyperText Transfer Protocol (HTTP) server. 

apxs是用来编译和安装 apache 服务器的扩展模块(mod)、也能生成项目模版(下面有具体使用说明)

名词解释:MinGW

MinGW,是Minimalist GNUfor Windows的缩写。它是一个可自由使用和自由发布的Windows特定头文件和使用GNU工具集导入库的集合,

允许你在GNU/Linux和Windows平台生成本地的Windows程序而不需要第三方C运行时(C Runtime)库。

MinGW 是一组包含文件和端口库,其功能是允许控制台模式的程序使用微软的标准C运行时(C Runtime)库(MSVCRT.DLL),该库在所有的 NT OS 上有效,

在所有的 Windows 95发行版以上的 Windows OS 有效,使用基本运行时,你可以使用 GCC 写控制台模式的符合美国标准化组织(ANSI)程序,

可以使用微软提供的 C 运行时(C Runtime)扩展,与基本运行时相结合,就可以有充分的权利既使用 CRT(C Runtime)又使用 WindowsAPI功能。





二、centos7.2 linux下开发 

0)(apache安装配置略)





1)安装 apxs


yum search apxs #查找apxs安装包,

yum install httpd-devel #apxs所在包,里面带的有apxs





2)建立一个开发目录

mkdir apachemod

进入apachemod目录

cd apachemod





3)用apxs建立一个mod模版

运行apxs -g -n helloworld(helloworld为模块名),会生成一个叫helloworld的目录和模板代码

模版代码如下:

=========================mod_helloworld.c===========================================

/* 

**  mod_helloworld.c -- Apache sample helloworld module

**  [Autogenerated via ``apxs -n helloworld -g'']

**

**  To play with this sample module first compile it into a

**  DSO file and install it into Apache's modules directory 

**  by running:

**

**    $ apxs -c -i mod_helloworld.c

**

**  Then activate it in Apache's httpd.conf file for instance

**  for the URL /helloworld in as follows:

**

**    #   httpd.conf

**    LoadModule helloworld_module modules/mod_helloworld.so

**    <Location /helloworld>

**    SetHandler helloworld

**    </Location>

**

**  Then after restarting Apache via

**

**    $ apachectl restart

**

**  you immediately can request the URL /helloworld and watch for the

**  output of this module. This can be achieved for instance via:

**

**    $ lynx -mime_header http://localhost/helloworld 

**

**  The output should be similar to the following one:

**

**    HTTP/1.1 200 OK

**    Date: Tue, 31 Mar 1998 14:42:22 GMT

**    Server: Apache/1.3.4 (Unix)

**    Connection: close

**    Content-Type: text/html

**  

**    The sample page from mod_helloworld.c

*/ 





#include "httpd.h"

#include "http_config.h"

#include "http_protocol.h"

#include "ap_config.h"





/* The sample content handler */

static int helloworld_handler(request_rec *r)

{

    if (strcmp(r->handler, "helloworld")) {

        return DECLINED;

    }

    r->content_type = "text/html";      





    if (!r->header_only)

        ap_rputs("小样,用C语言开发一个Apache的Module,这下牛逼了吧</br>在centos7.2上哦\n", r);

    return OK;

}





static void helloworld_register_hooks(apr_pool_t *p)

{

    ap_hook_handler(helloworld_handler, NULL, NULL, APR_HOOK_MIDDLE);

}





/* Dispatch list for API hooks */

module AP_MODULE_DECLARE_DATA helloworld_module = {

    STANDARD20_MODULE_STUFF, 

    NULL,                  /* create per-dir    config structures */

    NULL,                  /* merge  per-dir    config structures */

    NULL,                  /* create per-server config structures */

    NULL,                  /* merge  per-server config structures */

    NULL,                  /* table of config file commands       */

    helloworld_register_hooks  /* register hooks                      */

};

====================================================================================

4)编译并安装:

apxs -i -a -c mod_helloworld.c #运行之后生成的mod_helloworld.so

apxs生成之后会自动将

LoadModule helloworld_module  /usr/lib64/httpd/modules/mod_helloworld.so

这一行添加到apache.conf 文件中





centos终端编译效果如下图:





5)配置apache

我们要做的就是编辑 apache.conf

编辑命令:

vi /etc/httpd/conf/httpd.conf





找到 LoadModule helloworld_module  /usr/lib64/httpd/modules/mod_helloworld.so 这一行在下面加入





<Location /helloworld>

 setHandler helloworld

</Location>





:wq #进行保存





6)然后重启apache服务

service httpd restart

重启后查看一下咱们的服务状态:

serice httpd status

查看一下8080端口(我设置的是8080,你也可以按照你的实际来)

lsof -i:8080

出现:

# lsof -i:8080

COMMAND    PID   USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME

httpd   142314   root    4u  IPv6 1580018      0t0  TCP *:webcache (LISTEN)

httpd   142315 apache    4u  IPv6 1580018      0t0  TCP *:webcache (LISTEN)

httpd   142316 apache    4u  IPv6 1580018      0t0  TCP *:webcache (LISTEN)

httpd   142317 apache    4u  IPv6 1580018      0t0  TCP *:webcache (LISTEN)

httpd   142318 apache    4u  IPv6 1580018      0t0  TCP *:webcache (LISTEN)

httpd   142319 apache    4u  IPv6 1580018      0t0  TCP *:webcache (LISTEN)

httpd   142320 apache    4u  IPv6 1580018      0t0  TCP *:webcache (LISTEN)

表示一切正常





7)在浏览器里面输入http://loacalhost/helloworld,就可以看到我们返回的内容)

运行结果如下图:





     大功告成





8)centos的代码和编译后的so 模块下载地址

http://download.csdn.net/detail/tengyunjiawu_com/9811657





9)参考资料:

http://httpd.apache.org/docs/2.2/programs/apxs.html

C语言-apache mod(模块开发)-采用apxs开发实战(centos7.2 linux篇)的更多相关文章

  1. C语言-apache mod(模块开发)-采用VS2017开发实战(windows篇)

    C语言-apache mod(模块开发)-采用VS2017开发实战(windows篇) 名词解释:apxs apxs is a tool for building and installing ext ...

  2. 软件开发流变史:从瀑布开发到敏捷开发再到DevOps

    作为在20世纪70年代.80年代盛极一时的软件开发模型,瀑布模型通过制定计划.需求分析.软件设计.程序编写.软件测试.运行维护等6个流程将整个软件生命周期衔接起来.这6个流程有着严格的先后次序之分,只 ...

  3. Apache Solr采用Java开发、基于Lucene的全文搜索服务器

    http://docs.spring.io/spring-data/solr/ 首先介绍一下solr: Apache Solr (读音: SOLer) 是一个开源.高性能.采用Java开发.基于Luc ...

  4. Apache不重新编译,利用apxs工具给Apache添加模块,如cgi模块

    想实践下Apache是如何运行cgi程序的,却发现先前编译安装Apache的时候,没有安装Apache的cgi模块. 附:CentOS6.x编译安装LAMP(2):编译安装 Apache2.2.25 ...

  5. Apache Mod/Filter Development

    catalog . 引言 . windows下开发apache模块 . mod进阶: 接收客户端数据的 echo 模块 . mod进阶: 可配置的 echo 模块 . mod进阶: 过滤器 0. 引言 ...

  6. OSGi 系列(一)之什么是 OSGi :Java 语言的动态模块系统

    OSGi 系列(一)之什么是 OSGi :Java 语言的动态模块系统 OSGi 的核心:模块化.动态.基于 OSGi 就可以模块化的开发 java 应用,模块化的部署 java 应用,还可以动态管理 ...

  7. 10个强大的Apache开源模块

    1.单点登录模块 LemonLDAP LemonLdap可以很棒地实现Apache的SSO功能,并且可以处理超过 20 万的用户请求.LemonLdap支持Java, PHP, .Net, Perl, ...

  8. OSGi是什么:Java语言的动态模块系统(一)

    OSGi是什么 OSGi亦称做Java语言的动态模块系统,它为模块化应用的开发定义了一个基础架构.OSGi容器已有多家开源实现,比如Knoflerfish.Equinox和Apache的Felix.您 ...

  9. 开启Apache mod_rewrite模块(解决404 Not Found)

    网站搭建完成了,进入登录界面就是访问不了. 原因大概是没有开启Apache mod_rewrite模块,或者没有配置完全. 步骤1: 启用mod_rewrite模块 在conf目录的httpd.con ...

随机推荐

  1. 进度条ProgressBar

    在本节中,作者只写出了进度条的各种样式,包括圆形.条形,还有自定义的条形,我想如果能让条形进度条走满后再继续从零开始,于是我加入了一个条件语句.作者的代码中需要学习的是handler在主线程和子线程中 ...

  2. Visual C++中的ADO编程

    摘  要:本文介绍了微软推出的以ActiveX技术为基础的ADO数据存取技术,分析了ADO的工作原理,并用Visual C++说明了ADO数据访问技术的实现方法. 关键字:ADO:连接对象:OLE D ...

  3. Hdu2181 哈密顿绕行世界问题 2017-01-18 14:46 45人阅读 评论(0) 收藏

    哈密顿绕行世界问题 Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Sub ...

  4. Android类装载器DexClassLoader的简单使用-----制作android插件的前奏

    声明:此篇文章借鉴<android内核剖析>整理得来. 一.装载器简介 “类装载器”(ClassLoader),顾名思义,就是用来动态装载class文件的.标准的Java SDK中有个Cl ...

  5. Scala偏函数与部分函数

    函数 1.部分函数 部分应用函数(Partial Applied Function)是缺少部分参数的函数,是一个逻辑上概念. def sum(x: Int, y: Int, z: Int) = x + ...

  6. 如何获得 Microsoft Push Notification Service(MPNS)的最佳体验

    有很多同学抱怨MPNS的各种问题,其中包括服务超时.返回各种错误代码不知如何处理等等..今天我用一点时间来为大家介绍下如何处理和操作咱们的MPNS. 首先为大家明确一个问题,Microsoft Pus ...

  7. [Openwrt 项目开发笔记]:USB挂载& U盘启动(三)

    [Openwrt项目开发笔记]系列文章传送门:http://www.cnblogs.com/double-win/p/3888399.html 正文: 在上一篇中,我结合Netgear Wndr370 ...

  8. rtmp官方标准规范详细解析

    标准规范学习: rtmp消息结构,包括几个部分: 时戳:4  byte,单位毫秒.超过最大值后会翻转. 长度:消息负载的长度. 类型ID:Type Id 一部分ID范围用于rtmp的控制信令.还有一部 ...

  9. 实例化MD5CryptoServiceProvider报错:此实现不是 Windows 平台 FIPS 验证的加密算法的一部分

    System.InvalidOperationException: This implementation is not part of the Windows Platform FIPS valid ...

  10. js实现回车登陆

    2018-11-15 $(document).keydown(function (event) { if (event.keyCode == 13) { $("#LoginBtn" ...