Apache安装、配置、优化
点击次数:28 次 发布日期:2008-11-29 14:51:09 作者:源代码网
|
源代码网推荐 源代码网推荐 Apache 安装、配置、优化 源代码网推荐 安装 Apache 2.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 源代码网推荐 # make install 源代码网推荐 源代码网推荐 这个例子里面是编译了 mod_so,mod_speling 和 openssl 支持。 源代码网推荐 同样有另外几种写法 源代码网推荐 源代码网推荐 代码: 源代码网推荐 #./configure --enable-modules=so --enable-modules=speling --enable-modules=rewrite 源代码网推荐 源代码网推荐 或者 源代码网推荐 源代码网推荐 代码: 源代码网推荐 #./configure --enable-modules=”so speling” 源代码网推荐 源代码网推荐 --enable-MODULE[=shared] 编译并包含模块 MODULE. MODULE 是文档中去掉” _module ”的模块名。要将一个模块编译成为 DSO, 需要加 -shared 选项 , 即 --enable-mods-shared 。 (查看 MODULE 手册) 源代码网推荐 源代码网推荐 注意 :"如果希望核心能够装载 DSO,而不实际编译任何动态模块,则要明确指定 --enable-modules=so 或者 --enable-so" (查看 DSO 手册),所以前面的顺序不能交换顺序。 查看所有apache 的 configure 参数 源代码网推荐 源代码网推荐 安装完毕后可以用以下命令来查看启动了那些模块 源代码网推荐 源代码网推荐 代码: 源代码网推荐 # apachectl -l 源代码网推荐 Compiled in modules: 源代码网推荐 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.c mod_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/apachectl start" >> /etc/rc.d/rc.local 源代码网推荐 源代码网推荐 参考: 源代码网推荐 代码: 源代码网推荐 If you want your server to continue running after a system reboot , 源代码网推荐 you should add a call to apachectl to your system startup files (typically rc.local or 源代码网推荐 a file in an rc.N directory). This will start Apache as root. Before doing this ensure 源代码网推荐 that your server is properly configured for security and access restrictions. 源代码网推荐 源代码网推荐 在 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) 源代码网推荐 源代码网推荐 代码: 源代码网推荐 #chmod 755 ? R /home/dalouis/ 源代码网推荐 源代码网推荐 设置目录的可读性为 drwxr-xr-x(755), 否则会出现 "Forbidden You don"t have permission to access / on this server." 源代码网推荐 源代码网推荐 一些关于安全性的配置: 源代码网推荐 源代码网推荐 考虑到 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: Whether or not to allow persistent connections(more than 源代码网推荐 # one request per connection). Set to "Off" to deactivate. 源代码网推荐 源代码网推荐 # KeepAlive Off 源代码网推荐 源代码网推荐 # MaxKeepAliveRequests: The maximum number of requests to allow 源代码网推荐 # during a persistent connection. Set to 0 to allow an unlimited amount. 源代码网推荐 # We recommend you leave this number high, for maximum performance. 源代码网推荐 源代码网推荐 # MaxKeepAliveRequests 0 源代码网推荐 源代码网推荐 # KeepAliveTimeout: Number of seconds to wait for the next request 源代码网推荐 # from the same client on the same connection. 源代码网推荐 源代码网推荐 # KeepAliveTimeout 0 源代码网推荐 源代码网推荐 • 记录访问者的 HTTP-REFERER 和 AGENT, 有助于统计来者是通过什么搜索引擎找到我们的网站的。 或者在原有的CustomLog行,将参数由 common 改成 combined 源代码网推荐 源代码网推荐 代码: 源代码网推荐 # If you would like to have agent and referer logfiles, 源代码网推荐 # uncomment the following directives. 源代码网推荐 CustomLog logs/referer_log referer 源代码网推荐 CustomLog logs/agent_log agent 源代码网推荐 CustomLog logs/www.domain.com-access_log combined 源代码网推荐 源代码网推荐 使用 mod_limitipconn.c 来限制 apache 的并发数 源代码网推荐 源代码网推荐 Package: http://dominia.org/djao/limit/这里的安装建议使用动态 DSO 并 patch apache2.0, 以使得 apache2.0 可以认识在代理后方的 IP 。但是要 重新编译 apache2.0, 以下是介绍。 源代码网推荐 源代码网推荐 代码: 源代码网推荐 ##Instructions for building DSO with proxy tracking: 源代码网推荐 # tar xzvf httpd-2.0.39.tar.gz 源代码网推荐 # tar xzvf mod_limitipconn-0.22.tar.gz 源代码网推荐 # cd httpd-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 源代码网推荐 # make install 源代码网推荐 # cd ../mod_limitipconn-0.22 源代码网推荐 # PATH=/usr/local/apache2/bin:$PATH 源代码网推荐 # make install 源代码网推荐 安装过程 源代码网推荐 源代码网推荐 # lynx http://dominia.org/djao/limit/mod_limitipconn-0.22.tar.gz 源代码网推荐 # tar -zxvf mod_limitipconn-0.22.tar.gz 源代码网推荐 # cd httpd-2.0.48 源代码网推荐 # patch -p1 < ../mod_limitipconn-0.22/apachesrc.diff 源代码网推荐 patching file configure.in 源代码网推荐 Hunk #1 succeeded at 373 (offset 55 lines). 源代码网推荐 patching file include/scoreboard.h 源代码网推荐 patching file modules/generators/mod_status.c 源代码网推荐 Hunk #1 succeeded at 746 (offset -1 lines). 源代码网推荐 patching file server/scoreboard.c 源代码网推荐 # ./configure --enable-so --enable-speling --enable-rewrite --with-ssl=/usr/local/ssl --enable-forward 源代码网推荐 # make 源代码网推荐 # make install 源代码网推荐 # cd ../mod_limitipconn-0.22 源代码网推荐 # PATH=/usr/local/apache2/bin:$PATH 源代码网推荐 # make install 源代码网推荐 ---------------------------------------------------------------------- 源代码网推荐 Libraries have been installed in: 源代码网推荐 /usr/local/apache2/modules 源代码网推荐 If you ever happen to want to link against installed libraries 源代码网推荐 in a given directory, LIBDIR, you must either use libtool, and 源代码网推荐 specify the full pathname of the library, or use the `-LLIBDIR" 源代码网推荐 flag during linking and do at least one of the following: 源代码网推荐 - add LIBDIR to the `LD_LIBRARY_PATH" environment variable 源代码网推荐 during execution 源代码网推荐 - add LIBDIR to the `LD_RUN_PATH" environment variable 源代码网推荐 during linking 源代码网推荐 - use the `-Wl,--rpath -Wl,LIBDIR" linker flag 源代码网推荐 - have your system administrator add LIBDIR to `/etc/ld.so.conf" 源代码网推荐 See any operating system documentation about shared libraries for 源代码网推荐 more information, such as the ld(1) and ld.so(8) manual pages. 源代码网推荐 ---------------------------------------------------------------------- 源代码网推荐 chmod 755 /usr/local/apache2/modules/mod_limitipconn.so 源代码网推荐 [activating module `limitipconn" in /usr/local/apache2/conf/httpd.conf] 源代码网推荐 源代码网推荐 检查 httpd.conf 文件,发现增加了一下一行 源代码网推荐 源代码网推荐 代码: 源代码网推荐 LoadModule limitipconn_module modules/mod_limitipconn.so 源代码网推荐 源代码网推荐 同时需要设置以下参数在 httpd.conf 中 , 也可以在单个虚拟服务器中。 源代码网推荐 源代码网推荐 代码: 源代码网推荐 ExtendedStatus On 源代码网推荐 # Only needed if the module is compiled as a DSO 源代码网推荐 LoadModule limitipconn_module lib/apache/mod_limitipconn.so 源代码网推荐 <IfModule mod_limitipconn.c> 源代码网推荐 <Location /somewhere> 源代码网推荐 MaxConnPerIP 3 源代码网推荐 # exempting images from the connection limit is often a good 源代码网推荐 源代码网推荐 源代码网推荐 源代码网推荐 源代码网供稿. |
