⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1302.html

📁 著名的linux英雄站点的文档打包
💻 HTML
📖 第 1 页 / 共 3 页
字号:
                        <TD vAlign=top width="80%"> 
                          <DIV align=center>
                        <FORM action="search.html" tppabs="http://www.linuxhero.com/docs/search.html" method=get>
                            </FORM>
                        <TABLE cellSpacing=0 cellPadding=0 width="95%" 
                          border=0><TBODY>
                          <TR>
                            <TD background="images/bgi.gif" tppabs="http://www.linuxhero.com/docs/images/bgi.gif" 
                          height=30></TD></TR></TBODY></TABLE>
                        <TABLE cellSpacing=0 cellPadding=3 width="95%" 
                        align=center border=0>
                          <TBODY>
                          <TR>
                            <TD>
                              <TABLE cellSpacing=0 cellPadding=3 width="100%" 
                              border=0>
                                <TBODY>
                                <TR>
                                      <TD vAlign=top> 
<p><FONT class=normalfont><B><font color=blue>浅析Apache中SSI和CGI的设定方法</font></B></FONT><BR><FONT class=smallfont color=#ff9900>2004-04-23 15:18 pm</FONT><BR><FONT class=normalfont>作者:作者<br>来自:Linux知识宝库<br>联系方式:无名<br><br>由于Apache具有相当高的可移植性,它支持超过30种操作系统,包括Unix、Windows 及Darwin等系统,所以目前在网络上已注册的网域里大部份是使用Apache网页服务器。目前ApacheSoftware Foundation 正致力于发展现在已进入alpha测试阶段的Apache2.0。在这里,我和大家探讨如何修改服务器选项让服务器能提供简单的动态网页内容,也就是支持 CGI程序及 Server-Side Include(SSI)程序。<br>
1、准备工作<br>
首先,我假设你已经安装好Apache而且你的Apache能提供静态网页供浏览。Apache的安装会自动附上静态的HTML测试页,也就是说如果能看到那测试页,就代表你的 Apache能正常运作了。基本安装下的Apache仅能提供静态的HTML网页。然而,你可以通过使用模块(modules)来提升它的功能。在原始的设定下,Apache的编译会包含mod_include 及 moc_cgi 这两个模块。你可以在bin子目录下执行./httpd -l来查看你的Apache是否装有这两个模块。执行的输出会是一长串Apache现在安装的所有模块。如果mod_include及moc_cgi 这两个模块不在清单里,你必须重新编译服务器。重新编译时,确定依照如何含括 mod_include、moc_cgi 模块的说明。此外你还必需有提供实时网页的Server-Side Includes(相关资料网址:http: //www.oreilly.com/catalog/apache/excerpt/ch10.html)。有了 server-side includes (SSI)支持,你就能制作出实时的动态网页。接下来,我先从服务器的SSI支持设定开始,然后进入CGI的编写。<br>
2、Apache的设定<br>
首先你必须先找到Apache这个设定文件。Apache的原始安装目录在 Unix下是/usr/local/apache,在Windows下则是 c:Program FilesApache。接着在conf子目录下你会找到httpd.conf 文件。这就是Apache的设定档。这个设定文件是个纯文字文件,所以你可以使用一般的文字编辑器,如vi或Notepad 等,来编辑。首先要注意的是在这个设定档里有些行的起始文字是#符号,这表示这行的文字全为批注。适当地在你的设定档内做批注是个好习惯,因为那帮你记得你曾做了哪些设定以及为什么。<br>
3、执行 SSI 程序<br>
开启设定文件并寻找以下这些文字:<br>
#<br>
# To use server-parsedHTMLfiles<br>
#<br>
#AddType text/html .shtml<br>
#AddHandler server-parsed .shtml<br>
删除AddType及AddHandler这两行指令前的#符号。AddType指令会要求服务器在传回任何附属档名为.shtml的网页时,以 text或HTML做为传回文件的内容格式。AddHandler 则是用来指示服务器将文件内容送交给mod_include 处理。之后,mod_include 就会判断该如何响应这样的文件。接下来,寻找以下文字:<br>
在这行文字及对应的 间会有一行选项行(options line)。原始的设定是:<br>
Options Indexes FollowSymLinks MultiViews<br>
在这行尾端加上Includes ,结果看起来会是这样:<br>
Options Indexes FollowSymLinks MultiViews Includes<br>
这是要求Apache在htdocs子目录里执行 server-side includes 程序。为了让这些修改生效,我们必须重新启动服务器。在 Unix 下重新激活,执行"kill -HUP `cat /usr/local/apache/logs/httpd.pid`"。在 Windows 下,执行"Apache-k restart"。现在我们来试试刚才的设定结果。在/usr/local/apache/htdocs 目录里新增一个文件 test.shtml。这个文件必须要包含以下程序代码:<br>
The file hello.txt is long and it was last modified on<br>
这段 SSI 程序会去读取一个称为 hello.txt 文件,并将该文件的大小以及最近一次的修改日期输出到网页上。显然的,我们还必须在 htdocs 目录下新增这个hello.txt 文件。在我的hello.txt 文件里只有一行文字:HOW ARE YOU!。完成新增这些文件后,打开你惯用的浏览器并开启http://localhost/test.shtml网页。如果你服务器的安装并不是通过 root用户,你可能必须改为开启http://localhost:8080/test.shtml。之后将得到如下结果:<br>
HOW ARE YOU! The file hello.txt is 1k bytes long and it was last modified on Wednesday, 02-Aug-2000 20:18:28 PDT<br>
另外一种可以激活支持SSI程序的方法称为XbitHack设定(相关资料网址:http: //www.apache.org/docs/mod/mod_include.html#xbithack )。这个方法的由来是当你将文本文件的使用者可执行位(user-executable bit)设为可执行状态后,Apache会将那些文件视为 SSI 程序文件。<br>
要激活这样的功能必须将以下指令(directive)放在所有目录的 .htaccess 文件里:XbitHack status on (or full) status 的值可以设为on 、off 或是full。on 的设定会强制服务器将所有使用者可执行的文件视为SSI项。Off则使服务器完全忽略使用者可执行的设定状态。若是设定为Full,服务器会视所有使用者可执行档为SSI项,同时也会检查组可执行(group-executable bit)。如果组可执行项设定为可执行时,传回header的last modified time的值就会被设定为该文件最近一次被修改的时间。这样的设定可以让客户端的浏览器及代理服务器(proxy)进行缓存(caching)。不过在使用这样的功能时必须要小心。例如说,如果你的网页有提供轮替式广告看板你就不会想要设定群组可执行位为开启的状态,因为那么做会让第一个下载的广告被快取起来,导致使用者再也看不到其它页的广告。<br>
4、执行CGI程序<br>
在Apache原始安装里,cgi-bin子目录下附有两组CGI程序,test-cgi 以及printenv,只不过这两组程序有潜在的安全漏洞。但是由于我们只是要做设定测试,并且我们不会将这样的原始安装设定直接放在主运行服务器(live server),所以我们还是会激活其中一组CGI程序,看看Apache当初是如何被设定来执行这组程序。最后我们会自己撰写一支简单的CGI程序。<br>
首先,要确定这组程序是能执行的。进入cgi-bin子目录,确定程序文件被设定为使用者(服务器执行时使用者)可执行以及使用组(服务器执行时使用组)可执行。对 Windows系统来说,这一步应该是非必要的。接着,对服务器要求这样的内容:<br>
http://localhost:8080/cgi-bin/test-cgi<br>
注意:只有在通过非root使用者进行服务器安装的情况下才需要指定8080端口(port)。这支Apache内建的test-cgi程序会列出CGI程序会存取的变量值。激活CGI支持是设定在httpd.conf设定文件内的ScriptAlias 指令区段。这个指令区段的原始设定值是:<br>
ScriptAlias /cgi-bin/ "/usr/local/apache/cgi-bin/"<br>
这行指令是告诉Apache如果要求的网页路径是以cgi-bin为起始,这些文件可在/usr/local/apache/cgi-bin/ 目录下找得到。这行指令同时也告诉Apache要在这个目录下执行文件。在下面我准备了一个会输出"How are you!"的简单CGI程序。我将它命名为 how.sh。<br>
#!/bin/sh<br>
echo "Content-type: text/html"<br>
echo<br>
echo "How are you!"<br>
修改这个文件的权限使其成为可执行文件并且向你的服务器提出以下的要求:<br>
http://localhost:8080/cgi-bin/how.sh<br>
虽然这组CGI是采用shell script来编写,其实它可以用任何适用于该系统的语言来撰写。至于关于CGI程序的撰写如果有机会我会和大家作更深入的探讨。<br>
结论:<br>
Apache支持的所有SSI 指令可以在Apachedocumentation 里找到,Apache所有的功能都可以通过设定文件(config file)进行调试。在这里我所介绍的仅只是设定文件相关知识的皮毛。设定文件的原始设定有着非常详尽的说明文件,而且每一个系统版本都附有核心模块及标准模块的说明文件,如果你花些时间在这些文件里摸索,你会找到任何你想要的功能。 <br>
</FONT><br>
                                      </TD>
                                    </TR>
                                <TR>
                                <TD colSpan=2><FONT 
                                class=middlefont></FONT><BR>
                                        <FONT 
                                class=normalfont>全文结束</FONT> </TD>
                                    </TR>
                                <TR>
                                <TD background="images/dot.gif" tppabs="http://www.linuxhero.com/docs/images/dot.gif" colSpan=2 
                                height=10></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></DIV></TD>
                        <TD vAlign=top width="20%" 
                      background="images/line.gif" tppabs="http://www.linuxhero.com/docs/images/line.gif" rowSpan=2> 
                          <DIV align=center> 
                            <table class=tableoutline cellspacing=1 cellpadding=4 
                        width="100%" align=center border=0>
                              <tr class=firstalt> 
                                <td noWrap background="images/bgline.gif" tppabs="http://www.linuxhero.com/docs/images/bgline.gif" colspan=2 height=21>
                                <font class=normalfont><b>所有分类</b></font></td>
                              </tr>
<tr class=secondalt> <td noWrap width=27%> <font class=normalfont>1:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type1.html" tppabs="http://www.linuxhero.com/docs/type1.html">非技术类</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>2:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type2.html" tppabs="http://www.linuxhero.com/docs/type2.html">基础知识</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>3:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type3.html" tppabs="http://www.linuxhero.com/docs/type3.html">指令大全</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>4:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type4.html" tppabs="http://www.linuxhero.com/docs/type4.html">shell</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>5:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type5.html" tppabs="http://www.linuxhero.com/docs/type5.html">安装启动</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>6:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type6.html" tppabs="http://www.linuxhero.com/docs/type6.html">xwindow</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>7:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type7.html" tppabs="http://www.linuxhero.com/docs/type7.html">kde</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>8:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type8.html" tppabs="http://www.linuxhero.com/docs/type8.html">gnome</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>9:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type9.html" tppabs="http://www.linuxhero.com/docs/type9.html">输入法类</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>10:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type10.html" tppabs="http://www.linuxhero.com/docs/type10.html">美化汉化</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>11:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type11.html" tppabs="http://www.linuxhero.com/docs/type11.html">网络配置</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>12:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type12.html" tppabs="http://www.linuxhero.com/docs/type12.html">存储备份</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>13:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type13.html" tppabs="http://www.linuxhero.com/docs/type13.html">杂项工具</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>14:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type14.html" tppabs="http://www.linuxhero.com/docs/type14.html">编程技术</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>15:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type15.html" tppabs="http://www.linuxhero.com/docs/type15.html">网络安全</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>16:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type16.html" tppabs="http://www.linuxhero.com/docs/type16.html">内核技术</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>17:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type17.html" tppabs="http://www.linuxhero.com/docs/type17.html">速度优化</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>18:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type18.html" tppabs="http://www.linuxhero.com/docs/type18.html">apache</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>19:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type19.html" tppabs="http://www.linuxhero.com/docs/type19.html">email</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>20:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type20.html" tppabs="http://www.linuxhero.com/docs/type20.html">ftp服务</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>21:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type21.html" tppabs="http://www.linuxhero.com/docs/type21.html">cvs服务</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>22:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type22.html" tppabs="http://www.linuxhero.com/docs/type22.html">代理服务</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>23:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type23.html" tppabs="http://www.linuxhero.com/docs/type23.html">samba</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>24:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type24.html" tppabs="http://www.linuxhero.com/docs/type24.html">域名服务</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>25:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type25.html" tppabs="http://www.linuxhero.com/docs/type25.html">网络过滤</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>26:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type26.html" tppabs="http://www.linuxhero.com/docs/type26.html">其他服务</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>27:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type27.html" tppabs="http://www.linuxhero.com/docs/type27.html">nfs</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>28:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type28.html" tppabs="http://www.linuxhero.com/docs/type28.html">oracle</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>29:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type29.html" tppabs="http://www.linuxhero.com/docs/type29.html">dhcp</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>30:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type30.html" tppabs="http://www.linuxhero.com/docs/type30.html">mysql</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>31:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type31.html" tppabs="http://www.linuxhero.com/docs/type31.html">php</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>32:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type32.html" tppabs="http://www.linuxhero.com/docs/type32.html">ldap</a></font></td>    </tr>  </table></td></tr>                            </table>
                          </DIV></TD></TR>
                    <TR vAlign=top>
                        <TD width="80%"> 
                          <DIV align=center><BR>
                          </DIV>
                        </TD></TR></TBODY></TABLE></TD></TR>
                </TABLE></TD></TR>
          </TABLE>
      <TABLE cellSpacing=0 cellPadding=4 width="100%" bgColor=#eeeeee 
        border=0><TBODY>
        <TR>
          <TD width="50%">
              <P><FONT class=middlefont>版权所有 &copy; 2004 <A 
            href="mailto:bjchenxu@sina.com">linux知识宝库</A><BR>
                违者必究. </FONT></P>
            </TD>
          <TD width="50%">
              <DIV align=right><FONT class=middlefont>Powered by: <A 
            href="mailto:bjchenxu@sina.com">Linux知识宝库</A> Version 0.9.0 </FONT></DIV>
            </TD></TR></TBODY></TABLE>
      <CENTER></CENTER></TD></TR>
    </TABLE></CENTER></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -