📄 www-howto-7.html
字号:
可以依据用户的IP位址或网域名称来决定用户的存取权。这是一种把不速之客剔出用户名单的好方法[只要从log档案查出它们的IP位址及网域名称即可]。<P>要设定 Authentication,目录中<CODE>access.conf</CODE>档案中必须要有<CODE>AllowOverrides Authconfig</CODE>。而设定access control[使用网域名称或IP位址],则加入AllowOverrides Limit。<P>设定目录,就要在其中放入<CODE>.htaccess</CODE>档案。要设定使用者的Authentication,要用到<CODE>.htpasswd</CODE>档或外带一<CODE>.htgroup</CODE>档。这两个档还可由数个<CODE>.htaccess</CODE>档共用。<P>为了保全的理由,我个人建议,每个使用者都在他们的access.conf档使用下述指令:<P><BLOCKQUOTE><CODE><PRE><files ~ "/\.ht">order deny,allowdeny from all</files></PRE></CODE></BLOCKQUOTE><P>如果你不是系统管理员,但你的目录已经设为AllowOverride Limit,你仍然可以在你的 .htaccess档案中加入这些指令。他们可以防止别人偷窥你的access control档案[.htaccess 、.htpasswd等]。<P>Access control可运用在许多不同的选项及档案型式。这已超出本文的□畴。设定使用者 Authentication的信息,请参考<A HREF="javascript:if(confirm('http://www.apacheweek.com/features/userauth \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.apacheweek.com/features/userauth'" tppabs="http://www.apacheweek.com/features/userauth">http://www.apacheweek.com/features/userauth</A>,或NCSA的网页at <A HREF="javascript:if(confirm('http://hoohoo.ncsa.uiuc.edu/docs-1.5/tutorials/user.html \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://hoohoo.ncsa.uiuc.edu/docs-1.5/tutorials/user.html'" tppabs="http://hoohoo.ncsa.uiuc.edu/docs-1.5/tutorials/user.html">http://hoohoo.ncsa.uiuc.edu/docs-1.5/tutorials/user.html</A>。<P><H2><A NAME="ss7.10">7.10 su-exec</A></H2><P>su-exec功能能以owner的地位执行CGI script。平常都以网页服务器[不是一般的人]的地位来执行CGI script。因此,使用者不须将他们的CGI script的存取模式设为world writable[这是一个漏洞]。但是如果不熟悉su-exec,你可能会搞出更大的漏洞。平常su-exec在执行前会作保全检查,但如果设定错误,反而产生保全的漏洞。<P>su-exec不是设计给外行人用的。如果没有搞清楚,最好不要用,不然你搞出来的漏洞可以让使用者具备root存取能力。无论如何不要修改程序,要读通所有相关文件。su-exec那麽难设定,是故意设计出来让外行人知难而退[全部手动操作,没有make档,也没有安装script]。<P>su-exec是放在<CODE>support</CODE>目录中。首先要为系统修改<CODE>suexec.h</CODE>档,然後用下面的命令编译su-exec程序<P><BLOCKQUOTE><CODE><PRE>gcc suexec.c -o suexec</PRE></CODE></BLOCKQUOTE><P>然後将su-exec的可执行档复制到适当的目录。Apache的预设目录为<CODE>/usr/local/etc/httpd/sbin/</CODE>。如要改变预设目录,可修改Apache原始程序中的<CODE>httph</CODE>,在重新编译Apache。Apache只会搜寻该目录,而不会搜寻路径。另外要把su-exec的使用者改为root(<CODE>chown root suexec</CODE>),并且设定suid bit(<CODE>chmod 4711 suexec</CODE>)。最後重新启动Apache。此时Apache应该会在萤幕上显示su-exec正在运作。<P>CGI script仍要设为world executable。他们可以以CGI script owner的身份执行。如果设定他们的SUID[set user id]bit,则不会执行。如果他们的目录为world或group writable,也不会执行。如果owner为system user [root、bin等]也不会执行。相关保全状况,参考su-exec的文件。如果还有问题,检查su-exec的log档<CODE>cgi.log</CODE>。<P>在Apache的inetd模式,su-exec不运作,只有在daemon模式才运作。下一版可能会改善,因为inetd模式不会再用到了。要玩原始程序的话,就修改http.main.c。你可以删除其中使用su-exec wrapper的Apache宣告[它在每个输出之前居然都印一次]。<P>好好读一下Apache有关su-exec的文件。他们和su-exec的原始程序都在Apache网站中<A HREF="javascript:if(confirm('http://www.apache.org/docs/suexec.html \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.apache.org/docs/suexec.html'" tppabs="http://www.apache.org/docs/suexec.html">http://www.apache.org/docs/suexec.html</A>。<P><H2><A NAME="ss7.11">7.11 Imagemaps</A></H2><P>Apache能用来处理服务器端imagemaps。Imagemaps是网站上的图形,使用者点选图形中某个位置,可以用来决定要连结到那□去。要启动imagemaps,先确定imagemap模式是否已安装[它是预设要安装的一个模式]。然後将<CODE>srm.conf</CODE>档中的<CODE>.map</CODE> 标记开启[uncomment]。此时所有以<CODE>.map</CODE>结尾的档案都变成了imagemap档案。Imagemap档用一个图形的各个位置连结到不同的网页。Apache以标准NCSA格式使用投影[map]档。下述为投影档的一例:<P><BLOCKQUOTE><CODE><PRE><a href="/map/mapfile.map"><img src="picture.gif" ISMAP></a></PRE></CODE></BLOCKQUOTE><P>例中,<CODE>mapfile.map</CODE>即为投影档。而<CODE>picture.gif</CODE>为点选用的图形。<P>有很多程序可用来产生能与NCSA投影档共存的档案,你也可以自己编写一支。相关细节请参考:Apacheweek <A HREF="javascript:if(confirm('http://www.apacheweek.com/features/imagemaps \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.apacheweek.com/features/imagemaps'" tppabs="http://www.apacheweek.com/features/imagemaps">http://www.apacheweek.com/features/imagemaps</A>。<P><H2><A NAME="ss7.12">7.12 SSI/XSSI</A></H2><P>服务器端加入[SSI]可在静态的网页中以动态方式加入某些内容。要加入的项目在网页中以说明[comment]的方式表示。服务器先解析这些项目,然後将所要的内容加入。SSI可在档案中加入header及footer,也可以加入最後修改日期,也可执行系统命令或CGI script。如果使用延伸型伺服端加入[XSSI; eXtended Server Side Includes],可做的就更多了。它可加入变数及流程控制[如if、else等]。这简直就像一个在使用一个程序语言。<P>如要对每一个HTML档都加以解析,会消费太多系统资源。所以要有个方法使那些有SSI项目的档案看来不一样。一般的作法是,把这些HTML的延伸档名改为<CODE>.stml</CODE>。<P>要启用SSI/XSSI,首先确认是否该功能的模式已经安装。然後就可修改<CODE>srm.conf</CODE>档,为<CODE>.shml</CODE>型式的<CODE>AddType</CODE>及<CODE>AddHandler</CODE>开启[uncomment]。最後用<CODE>Options Includes</CODE>来定义那些目录下SSI/XSSI档可运行。这一步骤是在<CODE>access.conf</CODE>档中。那麽所有具<CODE>.shtml</CODE>延伸档名的档案都会被解析执行SSI/XSSI。<P>另一种在网页中加入内容的方式是使用<CODE>XBitHack</CODE>指令。这个指令一开启,它会检查该档案是否为user exectable。如果是,而且该目录用<CODE>Options Includes</CODE>开启的话,该档案就被视为SSI档案。但这种方式只对mime 型式的text/html[<CODE>.html .htm</CODE>档案]有效。所以不是最好的方法。<P>用SSI来执行系统命令及CGI script,会导致一些保全的风险。所以在<CODE>access.conf</CODE>档中最好使用<CODE>Option IncludesNOEXEC</CODE>而不要用Option Includes。其他SSI命令则不须修改。<P>相关细节参考原始程序附带的Apache mod-includes文件。可以从<A HREF="javascript:if(confirm('http://www.apache.org/docs/mod/mod_include.html \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.apache.org/docs/mod/mod_include.html'" tppabs="http://www.apache.org/docs/mod/mod_include.html">http://www.apache.org/docs/mod/mod_include.html</A>取得。<P>SSI/XSSI实现的相关细节参考Apacheweek<A HREF="javascript:if(confirm('http://www.apacheweek.com/features/ssi \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.apacheweek.com/features/ssi'" tppabs="http://www.apacheweek.com/features/ssi">http://www.apacheweek.com/features/ssi</A>.<P>有关SSI命令的信息,参考NCSA文件<A HREF="javascript:if(confirm('http://hoohoo.ncsa.uiuc.edu/docs/tutorials/includes.html \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://hoohoo.ncsa.uiuc.edu/docs/tutorials/includes.html'" tppabs="http://hoohoo.ncsa.uiuc.edu/docs/tutorials/includes.html">http://hoohoo.ncsa.uiuc.edu/docs/tutorials/includes.html</A>。<P>而有关XSSI命令的信息,参考<A HREF="javascript:if(confirm('ftp://pageplus.com/pub/hsf/xssi/xssi-1.1.html \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='ftp://pageplus.com/pub/hsf/xssi/xssi-1.1.html'" tppabs="ftp://pageplus.com/pub/hsf/xssi/xssi-1.1.html">ftp://pageplus.com/pub/hsf/xssi/xssi-1.1.html</A>。<P><H2><A NAME="ss7.13">7.13 模块系统</A></H2><P>Apache可用模块的方式加入任何东西。现在已有的模块很多,但只有一般常用的模块附带在Apache套件中。<P>要查查看还有那些模块,请参考Apache模块宝库<A HREF="javascript:if(confirm('http://www.zyzzyva.com/module_registry/ \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.zyzzyva.com/module_registry/'" tppabs="http://www.zyzzyva.com/module_registry/">http://www.zyzzyva.com/module_registry/</A>。<P>而有关模块化设计的信息,参考<A HREF="javascript:if(confirm('http://www.zyzzyva.com/module_registry/reference/ \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.zyzzyva.com/module_registry/reference/'" tppabs="http://www.zyzzyva.com/module_registry/reference/">http://www.zyzzyva.com/module_registry/reference/</A>。<P><P><P><P><HR><A HREF="WWW-HOWTO-8.html" tppabs="http://www.linux.org.tw/CLDP/gb/WWW-HOWTO-8.html"><IMG SRC="next.gif" tppabs="http://www.linux.org.tw/CLDP/gb/img/next.gif" ALT="Next"></A><A HREF="WWW-HOWTO-6.html" tppabs="http://www.linux.org.tw/CLDP/gb/WWW-HOWTO-6.html"><IMG SRC="prev.gif" tppabs="http://www.linux.org.tw/CLDP/gb/img/prev.gif" ALT="Previous"></A><A HREF="WWW-HOWTO.html#toc7" tppabs="http://www.linux.org.tw/CLDP/gb/WWW-HOWTO.html#toc7"><IMG SRC="toc.gif" tppabs="http://www.linux.org.tw/CLDP/gb/img/toc.gif" ALT="Contents"></A> </BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -