Linux(CentOs)下用 Apache构建HTTP服务器
# vi /etc/httpd/conf/httpd.conf ← 编辑Apache的配置文件 ## Don't give away too much information about all the subcomponents
# we are running. Comment out this line if you don't mind remote sites
# finding out what major optional modules you are running
ServerTokens OS ← 找到这一行,将“OS”改为“Prod”(在出现错误页的时候不显示服务器操作系统的名称)
↓
ServerTokens Prod ← 变为此状态
#
# Optionally add a line containing the server version and virtual host
# name to server-generated pages (internal error documents, FTP directory
# listings, mod_status and mod_info output etc., but not CGI generated
# documents or custom error documents).
# Set to "EMail" to also include a mailto: link to the ServerAdmin.
# Set to one of: On | Off | EMail
#
ServerSignature On ← 找到这一行,将“On”改为“Off”
↓
ServerSignature Off ← 在错误页中不显示Apache的版本
#
# ServerAdmin: Your address, where problems with the server should be
# e-mailed. This address appears on some server-generated pages, such
# as error documents. e.g. admin@your-domain.com
#
ServerAdmin root@localhost ← 将管理员邮箱设置为自己常用的邮箱
↓
ServerAdmin yourname@yourserver.com ← 根据实际情况修改默认设置
#
# ServerName gives the name and port that the server uses to> # This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If this is not set to valid DNS name for your host, server-generated
# redirections will not work. See also the UseCanonicalName directive.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
# You will have to access it by its address anyway, and this will make
# redirections work in a sensible way.
#
#ServerName new.host.name:80 ← 修改主机名
↓
ServerName www.centospub.com:80 ← 根据实际情况修改,端口号保持默认的80
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs-2.0/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks ← 找到这一行,删除“Indexes”,并添加“Includes”、“ExecCGI”
↓
Options Includes ExecCGI FollowSymLinks ← 允许服务器执行CGI及SSI
#
# AddHandler allows you to map certain file extensions to "handlers":
# actions unrelated to filetype. These can be either built into the server
# or added with the Action directive (see below)
#
# To use CGI scripts outside of ScriptAliased directories:
# (You will also need to add "ExecCGI" to the "Options" directive.)
#
#AddHandler cgi-script .cgi ← 找到这一行,去掉行首的“#”,并在行尾添加“.pl”
↓
AddHandler cgi-script .cgi .pl ← 允许扩展名为.pl的CGI脚本运行
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None ← 找到这一行,将“None”改为“All”
↓
AllowOverride All ← 变为此状态,允许.htaccess
#
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
#
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined ← 找到这一行
↓
LogFormat "%h %l %u %t \"%!414r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined ← 改为此状态(添加“!414”到规则中,对于过长的日志不记录)
#
# Specify a default charset for all pages sent out. This is
# always a good> # of your web site, should you ever want it. Specifying it as
# a default does little harm; as the standard dictates that a page
# is in iso-8859-1 (latin1) unless specified otherwise i.e. you
# are merely stating the obvious. There are also some security
# reasons in browsers,> # which encourage you to always set a default char set.
#
AddDefaultCharset UTF-8 ← 找到这一行,在行首添加“#”
↓
#AddDefaultCharset UTF-8 ← 不使用UTF-8作为网页的默认编码
AddDefaultCharset GB2312 ← 并接着添加这一行(添加GB2312为默认编码)
← 找到这一个标签,并在标签中更改相应选项
Options Indexes MultiViews ← 找到这一行,将“Indexes”删除
↓
Options MultiViews ← 变为此状态(不在浏览器上显示树状目录结构)
AllowOverride None
Order allow,deny
Allow from all
# rm -f /etc/httpd/conf.d/welcome.conf /var/www/error/noindex.html ← 删除测试页
页:
[1]