apache httpd动态添加模块

httpd添加新模块

有些时候因为特殊需求,需要在已安装的httpd上添加一些额外的模块,这时候要使用httpd-devel中的apxs工具。要使用这个扩展机制,你的平台必须支持DSO特性,即要求Apache httpd必须内建了mod_so模块。

安装好httpd后如果想添加新模块有两种方法:

  • 重新编译添加所需的模块
  • 使用工具动态添加,httpd支持

apxs工具添加模块的方法很简单,以下是几个可能用上的选项。

-c mod_foo.c:将c文件编译为.so文件。
-i:表示安装一个或多个模块到apache服务所在目录的modules目录中。
-a:表示自动在httpd.conf中加入LoadModule行。
-A:表示自动在httpd.conf中加入#LoadModule行,也就是说安装了模块但是不启用。
-n:显式指定-i需要安装的模块名

例:添加mod_proxy.so模块。

正确情况下:

[root@localhost ~]# cd /usr/local/src/httpd-2.4.43/modules
[root@localhost modules]# apxs -c -i -A proxy/mod_proxy.c proxy/proxy_util.c
......
chmod 755 /usr/local/apache/modules/mod_proxy.so
[preparing module `proxy' in /etc/apache/httpd.conf]

安装成功后的最后几行会告诉你要去修改配置文件,要修改配置文件中LoadModule指令来加载模块。


错误情况下:
有时候添加一个模块后重启失败了并提示undefined Symbol,说明还需添加另外相关的所需模块。

例如,上面如果只安装apxs -c -i -a proxy/mod_proxy.c时重启httpd。

httpd: Syntax error on line 120 of /etc/httpd/httpd.conf: Cannot load modules/mod_proxy.so into server: /app/
httpd/modules/mod_proxy.so: undefined symbol: ap_proxy_strmatch_domain

这说明还需要装相关的devel或者util对应的模块。

以上是转载大佬的:https://www.cnblogs.com/liujunjun/p/12049541.html

我当时安装proxy_util.c碰到的问题

proxy/proxy_util.c && touch proxy/proxy_util.sloproxy/proxy_util.c:27:57: fatal error: mod_http2.h: No such file or directory
#include “mod_http2.h” /* for http2_get_num_workers() */

找不到mod_http2.h,后来我改了proxy_util.c文件,

[root@localhost modules]# vim proxy/proxy_util.c
# 省略注释信息......
/* Utility routines for Apache proxy */
#include "mod_proxy.h"
#include "ap_mpm.h"
#include "scoreboard.h"
#include "apr_version.h"
#include "apr_hash.h"
#include "proxy_util.h"
#include "ajp.h"
#include "scgi.h"

#include "/usr/local/src/httpd-2.4.43/modules/http2/mod_http2.h" /* for http2_get_num_workers() */

默认选项为:#include "mod_http2.h" /* for http2_get_num_workers() */,我添加了它的绝对路径!

然后再安装就没问题了,以下安装信息!

要记得到配置文件中开启LoadModule 选项!

[root@localhost modules]# apxs -i -c -A proxy/mod_proxy.c proxy/proxy_util.c 

/app/httpd/build/libtool --silent --mode=compile gcc -std=gnu99 -prefer-pic   -DLINUX -D_REENTRANT -D_GNU_SOU
RCE -g -O2 -pthread -I/app/httpd/include  -I/app/httpd/include   -I/app/httpd/include   -c -o proxy/mod_proxy.lo proxy/mod_proxy.c && touch proxy/mod_proxy.slo/app/httpd/build/libtool --silent --mode=compile gcc -std=gnu99 -prefer-pic   -DLINUX -D_REENTRANT -D_GNU_SOU
RCE -g -O2 -pthread -I/app/httpd/include  -I/app/httpd/include   -I/app/httpd/include   -c -o proxy/proxy_util.lo proxy/proxy_util.c && touch proxy/proxy_util.slo/app/httpd/build/libtool --silent --mode=link gcc -std=gnu99    -o proxy/mod_proxy.la  -rpath /app/httpd/modu
les -module -avoid-version    proxy/proxy_util.lo proxy/mod_proxy.lo/app/httpd/build/instdso.sh SH_LIBTOOL='/app/httpd/build/libtool' proxy/mod_proxy.la /app/httpd/modules
/app/httpd/build/libtool --mode=install install proxy/mod_proxy.la /app/httpd/modules/
libtool: install: install proxy/.libs/mod_proxy.so /app/httpd/modules/mod_proxy.so
libtool: install: install proxy/.libs/mod_proxy.lai /app/httpd/modules/mod_proxy.la
libtool: install: install proxy/.libs/mod_proxy.a /app/httpd/modules/mod_proxy.a
libtool: install: chmod 644 /app/httpd/modules/mod_proxy.a
libtool: install: ranlib /app/httpd/modules/mod_proxy.a
libtool: finish: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/sbin" ldconfig -n /app/ht
tpd/modules----------------------------------------------------------------------
Libraries have been installed in:
   /app/httpd/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the '-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the 'LD_RUN_PATH' environment variable
     during linking
   - use the '-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to '/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
chmod 755 /app/httpd/modules/mod_proxy.so
[preparing module `proxy' in /etc/httpd/httpd.conf]

安装cgi模块

cd /usr/local/src/Apache-2.2.25/httpd-2.2.25/modules/generators
/usr/local/apache/bin/apxs -i -a -c mod_cgi.c

安装后会提示你更改权限,然后到配置文件中取消注释就好了

添加AJP模块

第一次使用apxs -i -c -A proxy/mod_proxy_ajp.c添加,当时命令执行成功了!到配置文件中修改了LoadModule ,然后httpd -t,报以下错误!还是undefined symbol真的不想看到它了!

[root@localhost modules]# apxs -i -c -A proxy/mod_proxy_ajp.c
[root@localhost modules]# httpd -t
httpd: Syntax error on line 129 of /etc/httpd/httpd.conf: Cannot load modules/mod_proxy_ajp.so into server: /
app/httpd/modules/mod_proxy_ajp.so: undefined symbol: ajp_send_header

解决方法:
如果第一次安装了mod_proxy_ajp.c,并且成功了,那么到httpd下的module目录中删掉已经编译安装的mod_proxy_ajp.so,然后执行下面的命令!

[root@localhost modules]# rm -f /app/httpd/modules/mod_proxy_ajp.so

[root@localhost modules]# pwd
/usr/local/src/httpd-2.4.43/modules		# 我的路径,根据自己的来

[root@localhost modules]# apxs -i -c -A proxy/mod_proxy_ajp.c  proxy/ajp*.c

说实话,我也不知道报错是什么!但是我安装的是ajp*.c,管你是什么,统统安装,然后再到配置文件中修改LoadModule,并检查 httpd -t 就没问题了!


可能每个人情况不同,但是记录每一个方法!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值