快捷搜索:   服务器  安全  linux 安全  MYSQL  dedecms

Apache安装配置优化(2)

  关于超时的问题

  在我编写好所有的产品查看页面的时候,经常会出现因为超时,或者流量过大 ,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

MaxConnPerIP 3
# exempting images from the connection limit is often a good
# idea if your web page has lots of inline images, since these
# pages often generate a flurry of concurrent image requests
# NoIPLimit image/*
# In this case, all MIME types other than audio/mpeg and video*
# are exempt from the limit check
# OnlyIPLimit audio/mpeg video

  注意: LoadModule limitipconn_module modules/mod_limitipconn.so 必须放在虚拟服务器之前!否则不能启动。

  定制 Apache index 目录

  在 Apache 中设置目录 有 Options Indexes 属性的时候,可以索引文件夹内容,但是如果要定制显示的内容,就必须添加以下几行到各个服务器的设置中去。(可以是全局,也可以是虚拟服务器或者目录) MODULE: mod_autoindex

  代码:

 

 ReadmeName /README.shtml
HeaderName /HEADER.shtml
IndexOptions +SuppressHTMLPreamble FancyIndexing VersionSort FoldersFirst NameWidth=* (Optoional) 

  但是,我在按照步骤,添加以上设置、设置文件夹可被索引属性、制作页首和页尾上传后,仍旧发现不能显示。最终发现,由于我安装了 PHP, 为了使得 PHP 代码可以被嵌入 .html 和 .htm 文档中,我将 httpd.conf 中的一条属性设置为:

  代码:

 

 AddType application/x-httpd-php .php .html .htm

  这使得 apache 不能识别原本设置的 README.html 和 HEADER.html,以下这点是从apache 的文档中找到类似的解说.

  参考:

  代码:

 

 Filename must resolve to a document with a major content
type of text/* ( e.g. , text/html , text/plain , etc.). This
means that filename may refer to a CGI script if the script's actual
file type (as opposed to its output) is marked as text/html such
as with a directive like:
AddType text/html .cgi
Content negotiation will be performed if Options MultiViews
is in effect. If filename resolves to a static text/html document
(not a CGI script) and either one of the options Includes
or IncludesNOEXEC is enabled, the file will be processed for
server-side includes (see the mod_include documentation). 

  我将上述 PHP 的 Type 的最终 .html 和 .htm 去掉以后,就可以正常显示了。于是想办法新添加一个种后缀名为 README 和 HEADER 专用:

  代码:

 

 AddType text/html .shtml

  然后修改 README.html 和 HEADER.html 为 README.shtml 和 HEADER.shtml 即可。

  要注意的是,因为我要列出的目录都为 open source, 所以有很多名字为“ README ”的文件。因此,要将其中的一条配置做小小的修改。(就是隐藏某些文件的配置)

  代码:

 IndexIgnore .??* *~ *# HEADER.* README.* RCS CVS *,v *,t 

顶(0)
踩(0)

您可能还会对下面的文章感兴趣:

最新评论