日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Apache模块开发

發布時間:2025/6/15 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Apache模块开发 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一、簡介

Apache HTTP服務器是一個模塊化的軟件,使管理者可以選擇核心中包含的模塊以裁剪功能。可以在編譯時選擇被靜態包含進httpd二進制映象的模塊,也可以編譯成獨立于主httpd二進制映象的動態共享對象DSO,DSO模塊可以在編譯服務器之后編譯,也可以用Apache擴展工具(apxs)編譯并增加。

Apache模塊開發主要采用掛鉤子的方法來實現模塊開發的,這和linux內核模塊開發有點像,說白了就是加一個回調函數。

?

二、安裝Apache的apxs

apxs是一個為Apache HTTP服務器編譯和安裝擴展模塊的工具,用于編譯一個或多個源程序或目標代碼文件為動態共享對象,使之可以用由mod_so提供的LoadModule指令在運行時加載到Apache服務器中。
?
apxs參考文檔:http://lamp.linux.gov.cn/Apache/ApacheMenu/programs/apxs.html
?
查看是否有httpd-devel這個包,如果沒有需要安裝

#rpm -qa | grep httpd #查看 #yum -y install httpd-devel #安裝

?

三、開發實例

程序1:apache模塊開發之內容生成器

執行以下命令,將生成helloworld的模板

apxs -g -n 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"/* 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("The sample page from mod_helloworld.c\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 */ };

編譯

apxs -c mod_helloworld.c

安裝

apxs -i mod_helloworld.la

修改配置文件httpd.conf,以加載模塊,主要添加如下內容

LoadModule helloworld_module modules/mod_helloworld.so <Location /helloworld>SetHandler helloworld </Location>

重啟服務器,進行測試

apachectl -k stop #停止apachectl -k start #啟動

在瀏覽器中輸入url,即可看到效果

http://127.0.0.1/helloworld

?

?

程序2:apache模塊開發之輸出過濾器

對于過濾器,有輸入過濾器與輸出過濾器兩種,有下面的順序:

請求--輸入過濾器--內容生成器--輸出過濾器--響應
所有的請求都會經過我們的過濾器,所以我們可以對這些進行操作,比如統計流量、數據壓縮等。下面示例可把頁面中所有的小寫字母變成大寫字母。

?

/** * @file: mod_casefilter.c * @brief: 把頁面中所有的小寫字母變成大寫字母 */?#include "httpd.h" #include "http_config.h" #include "apr_buckets.h" #include "apr_general.h" #include "apr_lib.h" #include "util_filter.h" #include "http_request.h"#include <ctype.h>static const char s_szCaseFilterName[]="CaseFilter"; module AP_MODULE_DECLARE_DATA case_filter_module;typedef struct {int bEnabled; } CaseFilterConfig;static void *CaseFilterCreateServerConfig(apr_pool_t *p,server_rec *s) {CaseFilterConfig *pConfig=apr_pcalloc(p,sizeof *pConfig);pConfig->bEnabled=0;return pConfig; }static void CaseFilterInsertFilter(request_rec *r) {CaseFilterConfig *pConfig=ap_get_module_config(r->server->module_config,&case_filter_module);if (!pConfig->bEnabled)return;ap_add_output_filter(s_szCaseFilterName,NULL,r,r->connection); }static apr_status_t CaseFilterOutFilter(ap_filter_t *f,apr_bucket_brigade *pbbIn) {request_rec *r = f->r;conn_rec *c = r->connection;apr_bucket *pbktIn;apr_bucket_brigade *pbbOut;pbbOut=apr_brigade_create(r->pool, c->bucket_alloc);for (pbktIn = APR_BRIGADE_FIRST(pbbIn);pbktIn != APR_BRIGADE_SENTINEL(pbbIn);pbktIn = APR_BUCKET_NEXT(pbktIn)){const char *data;apr_size_t len;char *buf;apr_size_t n;apr_bucket *pbktOut;if (APR_BUCKET_IS_EOS(pbktIn)){apr_bucket *pbktEOS=apr_bucket_eos_create(c->bucket_alloc);APR_BRIGADE_INSERT_TAIL(pbbOut,pbktEOS);continue;}/* read */apr_bucket_read(pbktIn,&data,&len,APR_BLOCK_READ);/* write */buf = apr_bucket_alloc(len, c->bucket_alloc);for (n=0 ; n < len ; ++n)buf[n] = apr_toupper(data[n]);pbktOut = apr_bucket_heap_create(buf, len, apr_bucket_free,c->bucket_alloc);APR_BRIGADE_INSERT_TAIL(pbbOut,pbktOut);}apr_brigade_cleanup(pbbIn);return ap_pass_brigade(f->next,pbbOut); }static const char *CaseFilterEnable(cmd_parms *cmd, void *dummy, int arg) {CaseFilterConfig *pConfig=ap_get_module_config(cmd->server->module_config,&case_filter_module);pConfig->bEnabled=arg;return NULL; }static const command_rec CaseFilterCmds[] = {AP_INIT_FLAG("CaseFilter", CaseFilterEnable, NULL, RSRC_CONF,"Run a case filter on this host"),{ NULL } };static void CaseFilterRegisterHooks(apr_pool_t *p) {ap_hook_insert_filter(CaseFilterInsertFilter,NULL,NULL,APR_HOOK_MIDDLE);ap_register_output_filter(s_szCaseFilterName,CaseFilterOutFilter,NULL,AP_FTYPE_RESOURCE); }module AP_MODULE_DECLARE_DATA case_filter_module = {STANDARD20_MODULE_STUFF,NULL,NULL,CaseFilterCreateServerConfig,NULL,CaseFilterCmds,CaseFilterRegisterHooks };

編譯

apxs -c mod_filter.c

安裝

apxs -i mod_filter.la

配置httpd.conf,添加如下內容:

LoadModule case_filter_module modules/mod_casefilter.soCaseFilter on

測試

總結

以上是生活随笔為你收集整理的Apache模块开发的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 日本色图片 | 久久久精品麻豆 | 亚洲综合日韩精品欧美综合区 | 免费网站av | 日操操 | 免费成人深夜在线观看 | 欧美日韩在线国产 | 拔擦8x成人一区二区三区 | 成人毛片18女人毛片 | 欧美人与性动交α欧美片 | 成人性生交免费看 | 成人毛片18女人 | 亚洲国产免费视频 | 国产精品一国产精品 | 悟空影视大全免费高清观看在线 | 亚洲高清资源 | 在线视频啪| 国产女女做受ⅹxx高潮 | 久久精品久久精品久久精品 | 亲子乱一区二区三区 | 亚洲欧美日韩一区 | 亚洲一级一级 | 嫩草影院懂你的影院 | 男人操女人视频网站 | 久久久久黄色 | 国模少妇一区二区三区 | 91av在线视频播放 | 色视屏| 欧美日韩一区二区三区国产精品成人 | 边添小泬边狠狠躁视频 | 夜夜操影视 | 丝袜av网站 | 日韩欧美网址 | 国产伦精品一区二区三区高清 | 国内免费精品视频 | 亚洲黄色大全 | 寡妇高潮一级视频免费看 | 国产亚洲精品美女 | 高清国产午夜精品久久久久久 | 91在线视频观看 | 北条麻妃在线一区 | 久久xx| 亚洲毛片网站 | 99视频99 | av收藏小四郎最新地址 | 日韩精品一区二区三区网站 | 免费处女在线破视频 | 波多野在线观看 | 免费精品在线观看 | 欧美www | 亚洲三级国产 | 久久久三级视频 | 亚洲精品福利视频 | 中文字幕一区二区三区精品 | 久久夜夜操妹子 | 亚洲视频黄 | 色网址在线观看 | 成人国产片女人爽到高潮 | 美女毛片在线 | 九九热精品在线观看 | 极品新婚夜少妇真紧 | 殴美性生活 | 三上悠亚亚洲一区 | 久久97| 久久e热| 日本午夜电影 | 国产精品久久久久久久一区二区 | 日韩中文av在线 | 日韩一区二区视频在线播放 | 国产欧美一区二区三区视频 | 亚洲一区二区三区四区不卡 | 久久久久麻豆 | 亚洲激情视频网站 | 亚欧中文字幕 | 国产超级av| 欧美精品在线免费 | 禁漫天堂在线 | 精品欧美激情精品一区 | 手机在线看片你懂的 | 日韩一区二区久久 | 97精品国产97久久久久久免费 | 中文国产字幕 | 成人在线观看你懂的 | 青青草原伊人网 | 成人av动漫在线 | 国产乱码一区二区 | 特级西西人体444www | 国产h视频在线观看 | 熟妇人妻中文字幕无码老熟妇 | 殴美黄色大片 | av成人在线播放 | 亚洲iv一区二区三区 | 亚洲做受高潮 | 久久久久久国产精品日本 | 好吊视频一区二区三区四区 | 激情五月亚洲 | 欧美激情视频在线播放 | 久久综合婷婷国产二区高清 | 国产网站免费在线观看 |