📄 mod_so.html
字号:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta name="keywords" content="Apache, 中文, 手册, 中文版, 中文手册, 中文版手册, 参考手册, 中文参考手册, 金步国" />
<meta name="description" content="Apache 2.2 中文版参考手册" />
<meta name="author" content="金步国" />
<link href="../style/css/manual-zip.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
<link href="../style/css/manual-zip-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
<link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
<title>mod_so - Apache 2.2 中文版参考手册</title>
</head>
<body><div id="page-header">
<p class="menu"><a href="../mod/index.html">模块索引</a> | <a href="../mod/directives.html">指令索引</a> | <a href="../faq/index.html">常见问题</a> | <a href="../glossary.html">词汇表</a> | <a href="../sitemap.html">站点导航</a></p><p class="apache">Apache HTTP Server 版本2.2</p><img alt="" src="../images/feather.gif" /></div>
<div class="up"><a href="./index.html"><img title="<-" alt="<-" src="../images/left.gif" /></a></div>
<div id="path"><a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">文档</a> > <a href="../index.html">版本2.2</a> > <a href="./index.html">模块</a></div>
<div id="translation-info"> <a href="../translator_announcement.html#thanks">致谢</a> | <a href="../translator_announcement.html#announcement">译者声明</a> | 本篇译者:<a href="mailto:csfrank@citiz.net">金步国</a> | 本篇译稿最后更新:2006年1月29日 | <a href="../translator_announcement.html#last_new">获取最新版本</a></div>
<div id="page-content"><div id="preamble"><h1>Apache模块 mod_so</h1>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#AAAAAA" class="module">
<tr><th><a href="module-dict.html#Description">说明</a></th><td>允许运行时加载DSO模块</td></tr>
<tr><th><a href="module-dict.html#Status">状态</a></th><td>扩展(E)</td></tr>
<tr><th><a href="module-dict.html#ModuleIdentifier">模块名</a></th><td>so_module</td></tr>
<tr><th><a href="module-dict.html#SourceFile">源文件</a></th><td>mod_so.c</td></tr>
<tr><th><a href="module-dict.html#Compatibility">兼容性</a></th><td>在Windows上这是一个基本模块(始终包含)</td></tr>
</table>
<h3>概述</h3>
<p>该模块在支持动态链接机制的操作系统上可以用来在Apache启动和重启时加载<a href="../dso.html">DSO</a>模块,而不用重新编译。</p>
<p>在Unix上,被加载的可执行代码通常来自于共享对象文件(一般以<code>.so</code>为扩展名),在Windows上则为<code>.so</code>或<code>.dll</code>扩展名。</p>
<div class="warning"><h3>警告</h3>
<p>用于Apache1.3的模块不能直接用于Apache2.0 。</p>
</div>
</div>
<div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="windows" id="windows">为Windows创建可加载模块</a></h2>
<div class="note"><h3>注意</h3><p>从Apache1.3.15开始,Windows上的模块名规则发生了变化,现在使用mod_foo.so格式的名字。</p></div>
<p>Apache模块的API对于Unix和Windows是一样的。许多模块在这两个平台间移植几乎不需要什么修改,除非那些依赖于Unix特定属性而Windows没有提供的模块。</p>
<p>如果一个模块可用,那么有两种方法使用它。在Unix上,可以被静态编译进服务器。因为用于Windows的Apache并没有相应于Unix下的<code>Configure</code>编译配置程序,模块的源文件必须被加进ApacheCore项目文件,并且它的符号(symbols)必须被添加到<code>os\win32\modules.c</code>文件。</p>
<p>第二种方法是编译为一个动态链接库(DLL),以便在运行期间使用<code><code class="directive">LoadModule</code></code>指令加载。这些模块DLL在Apache安装期间就已经安装好了,不需要你自己去编译。</p>
<p>为了将模块编译为DLL,需要对模块的源文件做一个小小的修改:模块记录(module record)必须从DLL导出(稍后将会创建,见下)。为了达到这个目的,请将<code>AP_MODULE_DECLARE_DATA</code>(在Apache头文件中定义的)添加到你的模块记录(module record)定义中。比如,如果你的模块有:</p>
<div class="example"><p><code>
module foo_module;
</code></p></div>
<p>将上述内容替换为:</p>
<div class="example"><p><code>
module AP_MODULE_DECLARE_DATA foo_module;
</code></p></div>
<p>注意,这仅在Windows上有效,因此该模块可以不加修改的直接在Unix上使用。另外,如果你对<code>.DEF</code>文件很熟悉,你也可以使用它代替前面的方法导出该模块。</p>
<p>要创建一个包含该模块的DLL文件,你还必须将它连接到在编译libhttpd.dll共享库时创建的libhttpd.lib导出库。你还可能需要修改编译器设置以确保Apache头文件被正确的加载了。这些库位于服务器根目录下的"modules"目录中。最好是从中抓出一个已经存在的模块.dsp文件来看看以确保编译环境配置无误,或者按照.dsp文检查编译器和连接器的选项也可。</p>
<p>这样将会为你的模块创建一个DLL版本。只要将它放置到<code>modules</code>目录下,并使用<code class="directive">LoadModule</code>指令加载即可。</p>
</div>
<div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="directive-section"><h2><a name="LoadFile" id="LoadFile">LoadFile</a> <a name="loadfile" id="loadfile">指令</a></h2>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#AAAAAA" class="directive">
<tr><th><a href="directive-dict.html#Description">说明</a></th><td>加载已命名的目标文件或库</td></tr>
<tr><th><a href="directive-dict.html#Syntax">语法</a></th><td><code>LoadFile <em>filename</em> [<em>filename</em>] ...</code></td></tr>
<tr><th><a href="directive-dict.html#Context">作用域</a></th><td>server config</td></tr>
<tr><th><a href="directive-dict.html#Status">状态</a></th><td>扩展(E)</td></tr>
<tr><th><a href="directive-dict.html#Module">模块</a></th><td>mod_so</td></tr>
</table>
<p>该指令用于在服务器启动或者重启时加载已命名目标文件或库,以用于加载需要被某些模块使用的额外代码。<em>Filename</em>可以是一个绝对路径或者相对于<code class="directive"><a href="core.html#serverroot">ServerRoot</a></code>的相对路径。</p>
<p>例如:</p>
<div class="example"><p><code>LoadFile libexec/libxmlparse.so</code></p></div>
</div>
<div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="directive-section"><h2><a name="LoadModule" id="LoadModule">LoadModule</a> <a name="loadmodule" id="loadmodule">指令</a></h2>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#AAAAAA" class="directive">
<tr><th><a href="directive-dict.html#Description">说明</a></th><td>加载目标文件或库,并将其添加到活动模块列表</td></tr>
<tr><th><a href="directive-dict.html#Syntax">语法</a></th><td><code>LoadModule <em>module filename</em></code></td></tr>
<tr><th><a href="directive-dict.html#Context">作用域</a></th><td>server config</td></tr>
<tr><th><a href="directive-dict.html#Status">状态</a></th><td>扩展(E)</td></tr>
<tr><th><a href="directive-dict.html#Module">模块</a></th><td>mod_so</td></tr>
</table>
<p>该指令加载目标文件或库<em>filename</em>并将模块结构名<em>module</em>添加到活动模块列表。<em>module</em>就是源代码文件中用于拼写<code>module</code>的外部变量名,并作为<a href="module-dict.html#ModuleIdentifier">模块标识符(Module Identifier)</a>列在模块文档中。例如:</p>
<div class="example"><p><code>
LoadModule status_module modules/mod_status.so
</code></p></div>
<p>加载了位于<code class="directive"><a href="core.html#serverroot">ServerRoot</a></code>下模块目录中指定的模块。</p>
</div>
</div>
<div id="footer">
<p class="apache">本文允许自由使用、分发、转载,但必须保留译者署名;详见:<a href="../translator_announcement.html#announcement">译者声明</a>。</p>
<p class="menu"><a href="../mod/index.html">模块索引</a> | <a href="../mod/directives.html">指令索引</a> | <a href="../faq/index.html">常见问题</a> | <a href="../glossary.html">词汇表</a> | <a href="../sitemap.html">站点导航</a></p></div>
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -