安装Apache2.0.48(查看Install手册) 考虑到以后要rewite_url来使google更加容易收录网站,特地添加了mod_rewrite。 同时为了限制流量,特别加了mod_limitpcnn.c补丁,所以多了一个–enable-forward选项。 建议安装完毕以后不要删除安装目录,以便以后升级时使用。 记得升级前关闭apache2.0 编译过程: 代码: #./configure–enable-so–enable-speling–enable-rewrite–with-ssl=/usr/local/ssl–enable-forward #make #makeinstall 这个例子里面是编译了mod_so,mod_speling和openssl支持。 同样有另外几种写法 代码: #./configure–enable-modules=so–enable-modules=speling–enable-modules=rewrite 或者 代码: #./configure–enable-modules=”sospeling” –enable-MODULE[=shared]编译并包含模块MODULE.MODULE是文档中去掉”_module”的模块名。要将一个模块编译成为DSO,需要加-shared选项,即–enable-mods-shared。(查看MODULE手册) 注意:”如果希望核心能够装载DSO,而不实际编译任何动态模块,则要明确指定–enable-modules=so或者–enable-so”(查看DSO手册),所以前面的顺序不能交换顺序。查看所有apache的configure参数 安装完毕后可以用以下命令来查看启动了那些模块 代码: #apachectl-l Compiledinmodules: core.c mod_access.c mod_auth.c mod_include.c mod_log_config.c mod_env.c mod_setenvif.c prefork.c http_core.c mod_mime.c mod_status.c mod_autoindex.c mod_asis.c mod_cgi.c mod_negotiation.c mod_dir.cmod_imap.c mod_actions.c mod_speling.c mod_userdir.c mod_alias.c mod_rewrite.c mod_so.c 接着,将启动程序放入开机程序中去。如果要启动ssl加密网页,则必须通过手动启动apache2.0(参见ssl部分) 代码: #echo”/usr/local/apache2/bin/apachectlstart”>>/etc/rc.d/rc.local 参考: 代码: Ifyouwantyourservertocontinuerunningafterasystemreboot, youshouldaddacalltoapachectltoyoursystemstartupfiles(typicallyrc.localor afileinanrc.Ndirectory).ThiswillstartApacheasroot.Beforedoingthisensure thatyourserverisproperlyconfiguredforsecurityandaccessrestrictions. 在profile里面添加以上的语句来设置路径,使得在bash下更容易控制apachectl,省去了输入路径的麻烦。 代码: #vi/etc/profile PATH=”$PATH:usr/local/apache2/bin:” 配置apache2.0 代码: #vi/usr/local/apache2/conf/httpd.conf 配置文件请看文件httpd.conf(设置文档目录为/home/dalouis/public_html) 代码: #chmod755?R/home/dalouis/ 设置目录的可读性为drwxr-xr-x(755),否则会出现”ForbiddenYoudon’thavepermissiontoaccess/onthisserver.” 一些关于安全性的配置: 考虑到cgi-bin的安全性问题,我们暂时将cgi-bin去掉。将所有httpd.conf中的所有关于cgi-bin的行加上#. Xiyang的配置 我用的:mod_limitipconn,mod_expires,mod_gzip,mod_php4,mod_so,mod_access,mod_alias,mod_userdir,mod_dir,mod_autoindex,mod_status,mod_mime,mod_log_config,http_core 关于超时的问题 在我编写好所有的产品查看页面的时候,经常会出现因为超时,或者流量过大,apache停止工作的问题,原因有二,一是代码的不科学性,二是apache的设置问题。 以下是对设置的一点改动: 代码: #KeepAlive:Whetherornottoallowpersistentconnections(morethan #onerequestperconnection).Setto”Off”todeactivate. #KeepAliveOff #MaxKeepAliveRequests:Themaximumnumberofrequeststoallow #duringapersistentconnection.Setto0toallowanunlimitedamount. #Werecommendyouleavethisnumberhigh,formaximumperformance. #MaxKeepAliveRequests0 #KeepAliveTimeout:Numberofsecondstowaitforthenextrequest #fromthesameclientonthesameconnection. #KeepAliveTimeout0 •记录访问者的HTTP-REFERER和AGENT,有助于统计来者是通过什么搜索引擎找到我们的网站的。或者在原有的CustomLog行,将参数由common改成combined 代码: #Ifyouwouldliketohaveagentandrefererlogfiles, #uncommentthefollowingdirectives. CustomLoglogs/referer_logreferer CustomLoglogs/agent_logagent CustomLoglogs/www.domain.com-access_logcombined 使用mod_limitipconn.c来限制apache的并发数 Package:http://dominia.org/djao/limit/这里的安装建议使用动态DSO并patchapache2.0,以使得apache2.0可以认识在代理后方的IP。但是要重新编译apache2.0,以下是介绍。 代码: ##InstructionsforbuildingDSOwithproxytracking: #tarxzvfhttpd-2.0.39.tar.gz #tarxzvfmod_limitipconn-0.22.tar.gz #cdhttpd-2.0.39 #patch-p1<../mod_limitipconn-0.22/apachesrc.diff #./buildconf #./configure–enable-so–enable-speling–enable-rewrite–with-ssl=/usr/local/ssl–enable-forward #make #makeinstall #cd../mod_limitipconn-0.22 #PATH=/usr/local/apache2/bin:$PATH #makeinstall 安装过程 #lynxhttp://dominia.org/djao/limit/mod_limitipconn-0.22.tar.gz #tar-zxvfmod_limitipconn-0.22.tar.gz #cdhttpd-2.0.48 #patch-p1<../mod_limitipconn-0.22/apachesrc.diff patchingfileconfigure.in Hunk#1succeededat373(offset55lines). patchingfileinclude/scoreboard.h patchingfilemodules/generators/mod_status.c Hunk#1succeededat746(offset-1lines). patchingfileserver/scoreboard.c #./configure–enable-so–enable-speling–enable-rewrite–with-ssl=/usr/local/ssl–enable-forward #make #makeinstall #cd../mod_limitipconn-0.22 #PATH=/usr/local/apache2/bin:$PATH #makeinstall ———————————————————————- Librarieshavebeeninstalledin: /usr/local/apache2/modules Ifyoueverhappentowanttolinkagainstinstalledlibraries inagivendirectory,LIBDIR,youmusteitheruselibtool,and specifythefullpathnameofthelibrary,orusethe`-LLIBDIR’ flagduringlinkinganddoatleastoneofthefollowing: -addLIBDIRtothe`LD_LIBRARY_PATH’environmentvariable duringexecution -addLIBDIRtothe`LD_RUN_PATH’environmentvariable duringlinking -usethe`-Wl,–rpath-Wl,LIBDIR’linkerflag -haveyoursystemadministratoraddLIBDIRto`/etc/ld.so.conf’ Seeanyoperatingsystemdocumentationaboutsharedlibrariesfor moreinformation,suchastheld(1)andld.so(8)manualpages. ———————————————————————- chmod755/usr/local/apache2/modules/mod_limitipconn.so [activatingmodule`limitipconn’in/usr/local/apache2/conf/httpd.conf] 检查httpd.conf文件,发现增加了一下一行 代码: LoadModulelimitipconn_modulemodules/mod_limitipconn.so 同时需要设置以下参数在httpd.conf中,也可以在单个虚拟服务器中。 代码: ExtendedStatusOn #OnlyneededifthemoduleiscompiledasaDSO LoadModulelimitipconn_modulelib/apache/mod_limitipconn.so
MaxConnPerIP3 #exemptingimagesfromtheconnectionlimitisoftenagood
|
Apache安装、配置、优化(for linux)
安装Apache2.0.48(查看Install手册) 考虑到以后要rewite_url来使google更加容易收录网站,特地添加了mod_rewrite。 同时为了限制流量,特别…