设为首页 收藏本站
查看: 801|回复: 0

[经验分享] apache模块开发

[复制链接]

尚未签到

发表于 2016-12-30 06:42:06 | 显示全部楼层 |阅读模式
解决公司jboss集群的问题,开始学习apache模块开发,开发的平台采用windows平台,是希望大家更加容易能够进入开发阶段,公司大部分都有vs2008.
1.安装apache 安装包 httpd-2.2.21-win32-x86-no_ssl.msi
   
一定要custom全部安装,否则就不会有includelib目录
2.配置apxs
  1)
安装apxs            安装包apxs_win32
  2)
安装Strawberry Perl 安装包strawberry-perl-5.16.3.1-32bit.msi
  3)
进入dos命令提示符,转到apxs安装目录下,输入perl Configure.pl,按要求填写apache的安装目录...\apache2.2和命令名称“httpd.exe”
  4)
通过上一步,就会在apache2.2\bin下生成apxs命令,并且在apache2.2目录下生成了build目录
  5)
修改在apache2.2build目录中的config_vars.mk文件
    
CC = gcc gcc改为cl.exe LD = g++g++改为link.exeCPP = gcc-Egcc-E删掉
  6)
设置apache下的bin的命令apxs的路径为环境变量,以放便在不进入具体安装目录下运行apxs
3.编译apache模块
   1)
运行Visual Studio 2008 命令提示(在开始的Microsoft Visual Studio 2008下可以找到)
   2)
运行apxs -g -n helloworld(helloworld为模块名),会生成一个叫helloworld的目录和模板代码
   3)
进入helloworld目录,编辑mod_helloworld.c
   4)
运行apxs -c -i -a mod_helloworld.c libapr-1.lib libaprutil-1.lib libapriconv-1.lib libhttpd.lib,生成mod_helloworld.so
   5)
mod_helloworld.so拷贝到Apache2.2\modules
   6)
修改Apache2.2\conf\httpd.conf,在末尾加上
     LoadModule helloworld_module \modules\mod_helloworld.so 
    <Location /helloworld>
  setHandler helloworld
    </Location>
    
   7)
启动apache,在IE里输入http://loacalhost/helloworld
 

/*
**  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"

static int printitem(void *rec,const char *key,const char *value)
{
request_rec *r = rec;
ap_rprintf(r,"<tr><th scope=\"row\">%s</th><td>%s</td></tr>\n",ap_escape_html(r->pool,key),ap_escape_html(r->pool,value));
return 1;

}
static void printtable(request_rec *r,apr_table_t *t,const char *caption,const char *keyhead,const char *valhead)
{
ap_rprintf(r,"<table><caption>%s</caption></table><thead><tr><th scope=\"col\">%s</th><th scope=\"col\">%s</th></tr></thead><tbody>",caption,keyhead,valhead);
apr_table_do(printitem,r,t,NULL);
ap_rputs("</tbody></table>\n",r);
}
/* The sample content handler */
static int helloworld_handler(request_rec *r)
{
ap_set_content_type(r,"text/html;charset=ascii");
ap_rputs("<!DOCUMENT HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n"
"<html><head><title>Apache module devlop</title></head><body><h1>apache is back</h1>",r);
printtable(r,r->headers_in,"request headers","header","value");
printtable(r,r->headers_out,"response headers","header","value");
ap_rputs("apache module develop from ibyoung.c\n", r);
if (strcmp(r->handler, "helloworld")) {
return DECLINED;
}
r->content_type = "text/html";      
if (!r->header_only)
ap_rputs("run success.c\n", r);

ap_rputs("</body></html>",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                      */
};

 

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-321196-1-1.html 上篇帖子: Apache POI 介绍 下篇帖子: apache jakarta common
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表