Apache 为网络管理员提供了丰富多彩的功能,包括目录索引、目录别名、内容协商、可配置的HTTP错误报告、CGI 程序的 SetUID 执行、子进程资源管理、服务器端图象映射、重写 URL、URL 拼写检查以及联机手册 man 等。也就是说,如果您在 Linux Server 上成功安装配置了 Apache 之后,您的计算机也将随着 Apache 的生效而摇身一变,成为一台名副其实的 Web Server,这种变化的确是激动人心的。 
在 Internet 时代,外部主页的发布已经成为树立公司形象的一个重要手段,而内部主页也成为公司管理的主要方式。但是,要想实现这些功能,首先应该把我们的 Linux Server 配置成为一台强大的 Web Server。本章将详细介绍如何配置 Apache 服务器。希望各位同仁能够通过阅读本片文章达到理论实践双丰收的目的,在很短的时间里迅速成为一名出色的网络管理员。 
1.2 所需资源 
1.2.1 所需包 
RedHat6.2 服务器安装 
1.2.2 所需配置文件 
/etc/httpd/conf/httpd.conf 系统自带,管理员配置 
/etc/httpd/conf/access.conf 系统自带,不需要修改 
/etc/httpd/conf/srm.conf 系统自带,不需要修改 
1.3 配置方案 
/etc/httpd/conf/httpd.conf 
说明:apache 主配置文件 
源文件: 
ServerType standalone 
#定义 WebServer 的启动方式为 standalone,以增强其对大量访问的及时响应性 
ServerRoot "/etc/httpd" 
#指定包含 httpd 服务器文件的目录 
LockFile /var/lock/httpd.lock 
PidFile /var/run/httpd.pid 
ScoreBoardFile /var/run/httpd.scoreboard 
Timeout 300 
#响应超时量,单位为秒 
KeepAlive On 
#允许用户建立永久连接 
MaxKeepAliveRequests 100 
KeepAliveTimeout 15 
MinSpareServers 5 
#要保留的空闲服务器进程的最小值 
MaxSpareServers 20 
#要保留的空闲服务器进程的最大值 
StartServers 8 
#系统启动时的守护进程数 
MaxClients 150 
#所能提供服务的最大客户端编号,大于它的部分被放入请求队列 
MaxRequestsPerChild 100 
LoadModule vhost_alias_module modules/mod_vhost_alias.so 
LoadModule env_module modules/mod_env.so 
LoadModule config_log_module modules/mod_log_config.so 
LoadModule agent_log_module  modules/mod_log_agent.so 
LoadModule referer_log_module modules/mod_log_referer.so 
LoadModule mime_modulemodules/mod_mime.so 
LoadModule negotiation_module modules/mod_negotiation.so 
LoadModule status_module modules/mod_status.so 
LoadModule info_modulemodules/mod_info.so 
LoadModule includes_modulemodules/mod_include.so 
LoadModule autoindex_module  modules/mod_autoindex.so 
LoadModule dir_module modules/mod_dir.so 
LoadModule cgi_module modules/mod_cgi.so 
LoadModule asis_modulemodules/mod_asis.so 
LoadModule imap_modulemodules/mod_imap.so 
LoadModule action_module modules/mod_actions.so 
LoadModule userdir_module modules/mod_userdir.so 
LoadModule alias_module  modules/mod_alias.so 
LoadModule rewrite_module modules/mod_rewrite.so 
LoadModule access_module modules/mod_access.so 
LoadModule auth_modulemodules/mod_auth.so 
LoadModule anon_auth_module  modules/mod_auth_anon.so 
LoadModule db_auth_module modules/mod_auth_db.so 
LoadModule digest_module modules/mod_digest.so 
LoadModule proxy_module  modules/libproxy.so 
LoadModule expires_module modules/mod_expires.so 
LoadModule headers_module modules/mod_headers.so 
LoadModule usertrack_module  modules/mod_usertrack.so 
LoadModule setenvif_modulemodules/mod_setenvif.so 
LoadModule perl_modulemodules/libperl.so 
LoadModule php3_modulemodules/libphp3.so 
ClearModuleList 
AddModule mod_vhost_alias.c 
AddModule mod_env.c 
AddModule mod_log_config.c 
AddModule mod_log_agent.c 
AddModule mod_log_referer.c 
AddModule mod_mime.c 
AddModule mod_negotiation.c 
AddModule mod_status.c 
AddModule mod_info.c 
AddModule mod_include.c 
AddModule mod_autoindex.c 
AddModule mod_dir.c 
AddModule mod_cgi.c 
AddModule mod_asis.c 
AddModule mod_imap.c 
AddModule mod_actions.c 
#AddModule mod_speling.c 
AddModule mod_userdir.c 
AddModule mod_alias.c 
AddModule mod_rewrite.c 
AddModule mod_access.c 
AddModule mod_auth.c 
AddModule mod_auth_anon.c 
AddModule mod_auth_db.c 
AddModule mod_digest.c 
AddModule mod_proxy.c 
AddModule mod_expires.c 
AddModule mod_headers.c 
AddModule mod_usertrack.c 
AddModule mod_so.c 
AddModule mod_setenvif.c 
AddModule mod_perl.c 
AddModule mod_php3.c 
Port 80 
#定义服务器所使用的 TCP 的端口号 
User nobody 
Group nobody 
#以上两行是分配给 httpd 的新用户的文件权限,出于安全的考虑把 
它们的权限设置成为最低。 
ServerAdmin root@weboa.com.cn 
#设置 Web 管理员的邮件地址 
ServerName WebOA 
#定义客户端从服务器读取数据时返回给客户端的主机名,其缺省值 
是 localhost,第一次安装 Linux 的时候经常这里出错。 
documentRoot "/home/weboa/jakarta-tomcat/webapps/weboa" 
#设置所有 Apache 文档的根目录,比如说,用户对 
http://www.weboa.com.cn/index.html 的访问请求,Apache 对它 
的响应是 /home/weboa/jakarta-tomcat/webapps/weboa/index.html 
Options FollowSymLinks 
AllowOverride None 
Options Indexes Includes FollowSymLinks 
AllowOverride None 
Order allow,deny 
Allow from all# 允许所有人访问 
UserDir public_html 
DirectoryIndex index.html index.htm index.shtml index.cgi 
#设置多种成功访问主页的方式,为的是提高系统的容错性 
AccessFileName .htaccess 
Order allow,deny 
Deny from all 
UseCanonicalName On 
TypesConfig /etc/mime.types 
DefaultType text/plain 
MIMEMagicFile share/magic 
HostnameLookups Off 
ErrorLog /usr/httpd/log/error_log 
LogLevel warn 
#定义那些错误类型被记录到错误日志中 
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined 
#所有的 LogFormat 都用来定义日志中的条目 
LogFormat "%h %l %u %t \"%r\" %>s %b" common 
LogFormat "%{Referer}i -> %U" referer 
LogFormat "%{User-agent}i" agent 
CustomLog /usr/httpd/log/access_log common 
ServerSignature On 
Alias /icons/ "/home/httpd/icons/" 
#定义虚拟主机目录与系统目录的对应关系 
Options Indexes MultiViews 
AllowOverride None 
Order allow,deny 
Allow from all 
scriptAlias /cgi-bin/ "/home/httpd/cgi-bin/" 
#定义 CGI 目录 
AllowOverride None 
Options ExecCGI 
Order allow,deny 
Allow from all 
IndexOptions FancyIndexing 
AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip 
AddIconByType (TXT,/icons/text.gif) text/* 
AddIconByType (IMG,/icons/image2.gif) image/* 
AddIconByType (SND,/icons/sound2.gif) audio/* 
AddIconByType (VID,/icons/movie.gif) video/* 
AddIcon /icons/binary.gif .bin .exe 
AddIcon /icons/binhex.gif .hqx 
AddIcon /icons/tar.gif .tar 
AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv 
AddIcon /icons/compressed.gif .Z .z .tgz .gz .zip 
AddIcon /icons/a.gif .ps .ai .eps 
AddIcon /icons/layout.gif .html .shtml .htm .pdf 
AddIcon /icons/text.gif .txt 
AddIcon /icons/c.gif .c 
AddIcon /icons/p.gif .pl .py 
AddIcon /icons/f.gif .for 
AddIcon /icons/dvi.gif .dvi 
AddIcon /icons/uuencoded.gif .uu 
AddIcon /icons/script.gif .conf .sh .shar .csh .ksh .tcl 
AddIcon /icons/tex.gif .tex 
AddIcon /icons/bomb.gif core 
AddIcon /icons/back.gif .. 
AddIcon /icons/hand.right.gif README 
AddIcon /icons/folder.gif ^^DIRECTORY^^ 
AddIcon /icons/blank.gif ^^BLANKICON^^ 
DefaultIcon /icons/unknown.gif 
ReadmeName README 
HeaderName HEADER 
AddEncoding x-compress Z 
AddEncoding x-gzip gz tgz 
AddLanguage en .en 
AddLanguage fr .fr 
AddLanguage de .de 
AddLanguage da .da 
AddLanguage el .el 
AddLanguage it .it 
LanguagePriority en fr de 
AddType application/x-httpd-php3 .php3 
AddType application/x-httpd-php3-source .phps 
AddType application/x-httpd-php .phtml 
AddType application/x-tar .tgz 
AddType text/html .shtml 
AddHandler server-parsed .shtml 
AddHandler imap-file map 
BrowserMatch "RealPlayer 4\.0" force-response-1.0 
BrowserMatch "Java/1\.0" force-response-1.0 
BrowserMatch "JDK/1\.0" force-response-1.0 
Alias /perl/ /home/httpd/perl/ 
SetHandler perl-script 
PerlHandler Apache::Registry 
Options +ExecCGI 
Alias /doc/ /usr/doc/ 
order deny,allow 
deny from all 
allow from localhost 
Options Indexes FollowSymLinks 
include /etc/httpd/conf/tomcat-apache.conf 
Alias /netcard "/home/weboa/jakarta-tomcat/webapps/weboa/net_card" 
Options Indexes FollowSymLinks 
allow from all 
CacheSize 5 
#定义缓存区大小,以 KB 为单位。可以根据需要和硬盘空间大小进行设置 
CacheGcInterval 4 
#每隔 4 小时检查缓存区,如果已经超过 CacheSize 就删除文件 
CacheMaxExpire 24 
#HTTP文件最多被保持 24 小时 
CacheLastModifiedFactor 0.1 
#定义 HTTP 文件失效期,缺省是 0.1 ,意思是说失效期=离最近一次修改的时间 X,比如离最近一次修改的时间是 5 小时,那么失效期就是 5X0.1=0.5小 时 
CacheDefaultExpire 1 
#这一指令提供一个缺省的时间(小时)来销毁缓存的文件,这些文件的最后更改时间不详。CacheMaxExpire 命令不覆盖这一设置 
## 以下是如何对一个目录进行登陆控制的方法 ## 在 /etc/httpd/conf/httpd.conf 中添加以下内容: 
Alias /weboa/ "/home/weboa/" 
Options Indexes MultiViews 
AllowOverride authconfig 
Order allow,deny 
Allow from all 
在 /home/weboa 目录下建立 .htaccess 文件 
authname "shared files" 
authtype basic 
authuserfile /etc/httpd/conf/passwd 
require valid-user 
在 /etc/httpd/conf 目录下执行命令生成认证文件 
htpasswd -c thj thj #创建认证文件和第一个名和密码 
htpasswd weboa weboa #添加其他用户名和密码 
### 以下是做虚拟主机的实现方法 ### 
需要在 /etc/httpd/conf/httpd.conf 中添加下列内容: 
Alias /webadmin/ "/home/weboa/webadmin/html/" 
Options Indexes MultiViews 
AllowOverride None 
Order allow,deny 
Allow from all 
NameVirtualHost 192.168.0.1 #虚拟域名的 DNS 服务器 
ServerAdmin root@weboa.com.cn #网管邮件地址 
documentRoot /home/weboa/webadmin/html/ #服务器页面目录 
ServerName webadmin.weboa.com.cn #服务器名称 
需要在 /var/named/name2ip.conf 中添加的内容: 
webadmin IN A 192.168.0.1 
1.4 测试及管理办法 
1.4.1 测试方法 
每当管理员更改了 Apache 的设置之后,都应执行 /etc/rc.d/init.d/httpd restart 使得更改生效。 
1.4.2 管理方法 
Apache 提供大量的日志文件,当 Apache 出错的时候,管理员可以根据 htppd.conf 中的 ErrorLog 定义的路径来诊断。具体方法是: 
tail -f /var/log/httpd/apache/error_log 
(本文已被浏览 2963 次)
|
|