<-
Apache > HTTP服务器 > 文档 > V2.0 > 模块

Apache模块 mod_so

说明 允许启动和重启时加载DSO模块
状态Extension
模块名so_module
源文件mod_so.c
兼容性 在Windows下是一个基本模块

概述

该模块在支持动态链接机制的操作系统上可以用来在Apache在启动和重启时加载DSO模块,而不用重新编译。

在Unix上,被加载的可执行代码通常来自于共享对象文件(一般以.so为扩展名),在Windows上则为.so.dll扩展名。

警告

用于Apache1.3的模块不能直接用于Apache2.0。

top

为Windows创建可加载模块

注意

从Apache1.3.15开始,Windows上的模块名规则发生了变化,现在使用mod_foo.so格式的名字,而不是以前的ApacheModuleFoo.dll。

Apache模块的API对于Unix和Windows是一样的。许多模块在这两个平台间移植几乎不需要什么修改,除非那些依赖于Unix特定属性而Windows没有提供的模块。

如果一个模块可用,那么有两种方法使用它。在Unix上,可以被静态编译进服务器。因为用于Windows的Apache并没有相应于Unix下的Configure编译配置程序,模块的源文件必须被加进ApacheCore项目文件,并且它的符号(symbols)必须被添加到os\win32\modules.c文件。

第二种方法是编译为一个动态链接库(DLL),以便在运行期间使用LoadModule指令加载。这些模块DLL在Apache安装期间就已经安装好了,不需要你自己去编译。

为了将模块编译为DLL,需要对模块的源文件做一个小小的修改:模块记录(module record)必须从DLL导出(稍后将会创建,见下)。为了达到这个目的,请将AP_MODULE_DECLARE_DATA(在Apache头文件中定义的)添加到你的模块的模块记录(module record)定义中。比如,如果你的模块有:

module foo_module;

将上述内容替换为:

module AP_MODULE_DECLARE_DATA foo_module;

Note that this will only be activated on Windows, so the module can continue to be used, unchanged, with Unix if needed. Also, if you are familiar with .DEF files, you can export the module record with that method instead.

Now, create a DLL containing your module. You will need to link this against the libhttpd.lib export library that is created when the libhttpd.dll shared library is compiled. You may also have to change the compiler settings to ensure that the Apache header files are correctly located. You can find this library in your server root's modules directory. It is best to grab an existing module .dsp file from the tree to assure the build environment is configured correctly, or alternately compare the compiler and link options to your .dsp.

This should create a DLL version of your module. Now simply place it in the modules directory of your server root, and use the LoadModule directive to load it.

top

LoadFile 指令

说明 加载已命名的目标文件或库
语法LoadFile filename [filename] ...
作用域server config
状态Extension
模块mod_so

该指令用于在服务器启动或者重启时加载已命名目标文件或库,以用于加载需要被某些模块使用的额外代码。Filename可以是一个绝对路径或者相对于ServerRoot的相对路径。

例如:

LoadFile libexec/libxmlparse.so

top

LoadModule 指令

说明 加载目标文件或库,并将其添加到活动模块列表
语法LoadModule module filename
作用域server config
状态Extension
模块mod_so

该指令加载目标文件或库filename并将模块结构名module添加到活动模块列表。module就是源代码文件中用于拼写module的外部变量名,并作为模块标识符(Module Identifier)列在模块文档中。例如:

LoadModule status_module modules/mod_status.so

加载了位于ServerRoot下模块目录中指定的模块。