You are on page 1of 45

7

Apache

www.huachu.cn

Apache

7.1

WWW

7.2

Red Hat Linux 9

7.3

Apache

7.4

7.5

7.6

Apache

Apache
Apache


Apache

197

Red Hat Linux 9

WWW

7.1

Apache
Apache
Apache 2.0

7.1.1

Apache
Apache
Apache 2.0

Apache

1Web
Internet WWWWorld Wide WebWeb
WWW Internet

Web

Web
Web
Web
Web
Web
Web
Web /
Apache IENetscapeMozilla
URL Web Web
Hypertext

Web
HTMLWWW HTTP TCP/IP 80
7-1

198

Apache

HTTP--
<--HTTP
Web Client

www.huachu.cn

Internet

HTTP--
<--HTTP
Web Server

7-1

Web

Web URL WWW


Web
WWW

2 Web
Netcrafthttp://news.netcraft.comApache Web
Web 7-2

7-2

Web

2003 7 Netcraft 40936076 Web 25856505 Web


Apache Web 63.16 % Microsoft IIS
10992195 26.85 %Apache Web
3Apache
Apache WWW Server HTTP NCSA httpd
1.3Apache
HTTP Server
199

Red Hat Linux 9

HTTP
Apache Apache A Patchy
Server Patch
Apache 7-1
7-1 Apache

1995.3

Apache 0.6.2

1995.8

Apache 0.8.8

1995.10.1

Apache 1.0.0

1996.7

Apache 1.1 HTTP1.1

1997.6

Apache 1.2

1998.3

Apache 1.3

1998.6.12

mod_perl 1.0.0

2000

Apache 2.0

2002

Apache 2.0

4ASF
Apache Apache Group 1999 6 Apache Group
Apache Apache Software
FoundationASF
ASF Apache PerlPHPJava
TclXML ASF http://www.apache.org
5 Apache
Apache
Yahoo

7.1.2

IBM
Amasom.com
Hotmail.com
Red Hat

Apache

1Apache 1.3
Web Apache

(DSO)

200

Apache

www.huachu.cn

HTTP 1.1

HTTP

Socket SSL

CGI
Perl
SSI
FastCGI
PHP
Java Servlets

2Apache 2.0
Apache 2.0 Apache 1.3 Apache 2.0
Apache Portable RuntimeAPR
Apache

Apache 2.0 Multi-Processing ModuleMPM

Apache Apache 3

ProforkMPM Apache 1.3

WorkerMPM

PerchildMPM UNIX
201

Red Hat Linux 9

MPM

Apache

7.1.3

Apache 2.0

Apache 1.3 Apache 2.0 Apache


3 7.2 Apache 2.0
7-2 Apache 2.0

Core

Apache HTTP

mpm_common

MPM

mpm_netware

Novell NetWare MPM

mpm_winnt

Windows NT MPM

Perchild

Perchild MPM

Prefork

Profork MPM

Worker

Worker MPM

mod_access

IP

mod_actions

CGI

mod_alias

URL

mod_asis

HTTP

mod_auth

mod_auth_anon

mod_auth_dbm

DBM

mod_auth_digest

MD5

mod_autoindex

Unix ls Win32 dir shell

mod_cache

URI cache

mod_cern_meta

CERN httpd

mod_cgi

CGI MPM

mod_cgid

CGI MPM

mod_charset_lite

mod_dav

DAV

mod_deflate

mod_dir

trailing slash

mod_echo

mod_env

CGI SSI

mod_example

Apache API

mod_expires

HTTP

202

Apache

www.huachu.cn

mod_ext_filter

mod_file_cache

mod_headers

HTTP

mod_imap

mod_include

SSI

mod_info

mod_isapi

Apache Windows ISAPI

mod_log_config

mime
mod_mime

mod_mime_magic

MIME

mod_negotiation

mod_proxy

HTTP/1.1 /

mod_rewrite

URL

mod_setenvif

mod_so

mod_speling

URL

mod_ssl

SSL TLS

mod_status

mod_suexec

CGI

mod_unique_id

mod_userdir

mod_usertrack

mod_vhost_alias

http://modules.apache.org

Red Hat Linux 9

7.2

Apache
Red Hat Linux 9

Apache
Apache

203

Red Hat Linux 9

7.2.1

Apache

1 RPM Apache
Red Hat Linux 9 Apache 2.0
httpdApache 2.0
httpd-manualApache 2.0
RPM Apache Red Hat
Apache
7.1

Apache 2.0

// Apache
# rpm -qa|grep httpd
// Red Hat Linux 9 1
# mount /mnt/cdrom
// Red Hat/RPMS
# cd /mnt/cdrom/Red Hat/RPMS
// RPM
# rpm ivh httpd-2.0.40-21.i386.rpm
# rpm -ivh httpd-manual-2.0.40-21.i386.rpm
//
# cd;eject

2 Apache
Apache Red Hat Linux 9 Apache

7.2

Apache

//
# service httpd start
// httpd
# pstree|grep httpd
|- httpd---8*[httpd]
//
#
//
# apachectl configtest
httpd: Could not determine the server's fully qualified domain name,
using 127.0.0.1 for ServerName
Syntax OK
#
//
# service httpd status
204

Apache

www.huachu.cn

httpd (pid 2759 2758 2757 2756 2755 2754 2753 2752 2749) ...
#

1 httpd

# ntsysv
httpd
2
# httpd -t

7.2.2

Red Hat Linux 9

1 Red Hat Apache 2.0


Red Hat Apache 2.0
7.3

Red Hat Apache 2.0

//
# apachectl -V
Server version: Apache/2.0.40
Server built: Feb 25 2003 05:01:56
Server's Module Magic Number: 20020628:0
Architecture: 32-bit
Server compiled with....
-D APACHE_MPM_DIR="server/mpm/prefork"
-D APR_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6
-D APR_USE_SYSVSEM_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D HTTPD_ROOT="/etc/httpd"
-D SUEXEC_BIN="/usr/sbin/suexec"
-D DEFAULT_PIDLOG="logs/httpd.pid"
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
-D DEFAULT_LOCKFILE="logs/accept.lock"
-D DEFAULT_ERRORLOG="logs/error_log"
-D AP_TYPES_CONFIG_FILE="conf/mime.types"
-D SERVER_CONFIG_FILE="conf/httpd.conf"
#
//
# apachectl -l
Compiled in modules:

205

Red Hat Linux 9


core.c
prefork.c
http_core.c
mod_so.c
#

1
mod_so.c
Apache Dynamic Shared
ObjectsDSO Apache APache
eXtenSionapxs Apache
2 prefork.c Red Hat Apache
ProforkMPM

2Red Hat Linux 9


Red Hat Linux 9 httpd
/etc/httpd/conf/httpd.conf
Apache Red Hat Linux 9
7.4

Apache Red Hat 9

//
# grep -v "#" /etc/httpd/conf/httpd.conf
//header Apache
ServerTokens OS
//
ServerRoot "/etc/httpd"
// Apache PidFile
PidFile run/httpd.pid
// 300
Timeout 300
//
/ On
KeepAlive Off
//
MaxKeepAliveRequests 100
// 15
KeepAliveTimeout 15
// prefork MPM Red Hat
<IfModule prefork.c>
//
StartServers
8
//Apache
// 5
MinSpareServers
5
// 20

206

Apache

www.huachu.cn

MaxSpareServers 20
// 150
MaxClients
150
// 1000
MaxRequestsPerChild 1000
</IfModule>
// worker MPM
<IfModule worker.c>

</IfModule>
// perchild MPM
<IfModule perchild.c>

</IfModule>
//
Listen 80
///etc/httpd/conf.d conf
Include conf.d/*.conf
//(DSO)
LoadModule access_module modules/mod_access.so
LoadModule auth_module modules/mod_auth.so

LoadModule proxy_connect_module modules/mod_proxy_connect.so


// prefork.c cgi_module
<IfModule prefork.c>
LoadModule cgi_module modules/mod_cgi.so
</IfModule>
// worker.c cgid_module
<IfModule worker.c>
LoadModule cgid_module modules/mod_cgid.so
</IfModule>
// Apache
User apache
Group apache
// Apache E-mail
ServerAdmin root@localhost
// Apache
//ServerName:Port www.jamond.net:80
// www.jamond.net port 80

207

Red Hat Linux 9


UseCanonicalName Off
//
DocumentRoot "/var/www/html"
// Apache
<Directory />
//
Options FollowSymLinks
//.htaccess
AllowOverride None
</Directory>
//
<Directory "/var/www/html">
//Indexes DirectoryIndex
//

//FollowSymLinks
Options Indexes FollowSymLinks
//.htaccess
AllowOverride None
// Allow Deny
Order allow,deny
// Allow
Allow from all
</Directory>
// Apache
<LocationMatch "^/$>
Options -Indexes
ErrorDocument 403 /error/noindex.html
</LocationMatch>
//
<IfModule mod_userdir.c>
UserDir disable
</IfModule>
// index.htmlindex.html.var
DirectoryIndex index.html index.html.var
//
AccessFileName .htaccess
//.ht .htaccess
<Files ~ "^\.ht">
Order allow,deny
Deny from all

208

Apache

www.huachu.cn

</Files>
// MIME
TypesConfig /etc/mime.types
// MIME HTML
DefaultType text/plain
// mod_mime_magic.c Magic
<IfModule mod_mime_magic.c>
MIMEMagicFile conf/magic
</IfModule>
// Apache IP
HostnameLookups Off
//
ErrorLog logs/error_log
// warn
LogLevel warn
//
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""
combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
// combined

CustomLog logs/access_log combined


// Apache Apache
ServerSignature On
//
Alias /icons/ "/var/www/icons/"
///var/www/icons
<Directory "/var/www/icons">
// MultiViews
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
// Apche
Alias /manual "/var/www/manual"
///var/www/manual
<Directory "/var/www/manual">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
209

Red Hat Linux 9


Allow from all
</Directory>
// DAV
<IfModule mod_dav_fs.c>
DAVLockDB /var/lib/dav/lockdb
</IfModule>
// CGI
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
// Red Hat worker MPM mod_cgid.c
<IfModule mod_cgid.c>
Scriptsock
run/httpd.cgid
</IfModule>
// CGI
<Directory "/var/www/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
//
// FancyIndexing
// VersionSort
// NameWidth=*
IndexOptions FancyIndexing VersionSort NameWidth=*
// IndexOptions FancyIndexing
// MIME
//
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/*
// IndexOptions FancyIndexing
//
//
AddIcon /icons/binary.gif .bin .exe

AddIcon /icons/blank.gif ^^BLANKICON^^


// IndexOptions FancyIndexing
//
DefaultIcon /icons/unknown.gif
// README.html

210

Apache

www.huachu.cn

ReadmeName README.html
// HEADER.html
HeaderName HEADER.html
//.Z .gz .tgz
//
AddEncoding x-compress Z
AddEncoding x-gzip gz tgz
//
//
AddLanguage da .dk

AddLanguage hr .hr
//
LanguagePriority en da nl et fr de el it ja kr no pl pt pt-br ltz ca es sv
tw
// Prefer LanguagePriority 1
// Fallback LanguagePriority 1
ForceLanguagePriority Prefer Fallback
//
AddDefaultCharset ISO-8859-1
//
AddCharset ISO-8859-1 .iso8859-1 .latin1

AddCharset shift_jis .sjis


// MIME /etc/mime.types
AddType application/x-tar .tgz
// Apache
AddHandler imap-file map
AddHandler type-map var
// SSI
AddOutputFilter INCLUDES .shtml
//
Alias /error/ "/var/www/error/"
///var/www/error
<IfModule mod_negotiation.c>
<IfModule mod_include.c>
<Directory "/var/www/error">
AllowOverride None
Options IncludesNoExec
AddOutputFilter Includes html
AddHandler type-map var
211

Red Hat Linux 9


Order allow,deny
Allow from all
LanguagePriority en es de fr
ForceLanguagePriority Prefer Fallback
</Directory>
//
ErrorDocument 400 /error/HTTP_BAD_REQUEST.html.var
ErrorDocument 401 /error/HTTP_UNAUTHORIZED.html.var

ErrorDocument 506 /error/HTTP_VARIANT_ALSO_VARIES.html.var


</IfModule>
</IfModule>
//
BrowserMatch "Mozilla/2" nokeepalive
BrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0
BrowserMatch "RealPlayer 4\.0" force-response-1.0
BrowserMatch "Java/1\.0" force-response-1.0
BrowserMatch "JDK/1\.0" force-response-1.0
BrowserMatch
"Microsoft Data
Access
Internet
Publishing
Provider"
redirect-carefully
BrowserMatch "^WebDrive" redirect-carefully
#

Red Hat 9 Apache


/etc/httpd/conf/httpd.conf
/etc/httpd
/var/www/html
/var/log/httpd/access_log
/var/log/httpd/error_log
Apache apache
Apache apache
80
/usr/lib/httpd/modules
prefork MPM
StartServers 8
MinSpareServers 5
MaxSpareServers 20
MaxClients 150
MaxRequestsPerChild 1000

212

Apache

www.huachu.cn

Apache

7.3



Web

7.3.1

Apache
Include .htaccess
Web

1KeepAlive
KeepAlive On
2MaxClients

3ServerAdmin
ServerAdmin Apache E-mail
4ServerName
ServerName #
FQDN
5DirectoryIndex
index.htm
6IndexOptions
FoldersFirst

7.3.2

1 Include
Include

213

Red Hat Linux 9

Red Hat Linux 9 Include Include conf.d/*.conf


/etc/httpd/conf.d conf
2.htaccess
.htaccess
.htaccess Include .htaccess
Include

1.htaccess .htaccess


.htaccess .htaccess

2.htaccess
.htaccess
.htaccess
3.htaccess
1
AccessFileName .htaccess
<Files ~ "^\.htaccess">
Order allow,deny
Deny from all
</Files>

2.htaccess .htaccess
AllowOverride 7-3 AllowOverride

7-3 AllowOverride

AuthConfig
FileInfo
Indexes

214

AuthDBMGroupFile, AuthDBMUserFile, AuthGroupFile,

AuthName, AuthType, AuthUserFile, Require

DefaultType, ErrorDocument, ForceType, LanguagePriority,

SetHandler, SetInputFilter, SetOutputFilter


AddDescription, AddIcon, AddIconByEncoding, AddIconByType,

Apache

www.huachu.cn

DefaultIcon, DirectoryIndex, FancyIndexing, HeaderName,


IndexIgnore, IndexOptions, ReadmeName

Limit

Allow,Deny,Order

Options

Options, XBitHack

All

None

.htaccess

4.htaccess
.htaccess
.htaccess .htaccess
AllowOverride
5.htaccess
.htaccess
7.5

.htaccess

// private
# cd /var/www/html
# mkdir private
# cd private
# touch test
// 7-3
//
# vi /etc/httpd/conf/httpd.conf
//
<Directory "/var/www/html/private">
AllowOverride Options
</Directory>
#
// httpd
# service httpd restart
///var/www/html/private .htaccess
# vi /var/www/html/private/.htaccess
//
Options Indexes
#
// 7-4
//.htaccess private
//

215

Red Hat Linux 9

7.3.3

7-3

.htaccess

7-4

.htaccess

Apache .htaccess
.htaccess

Web

1
Web Apache
Web
Web
Web
Web
216

Apache

www.huachu.cn

7.6

Web

//
# vi /etc/httpd/conf/httpd.conf
//
<IfModule mod_userdir.c>
// root
UserDir disable root
// Web
UserDir public_html
</IfModule>
// Web #
<Directory /home/*/public_html>
AllowOverride FileInfo AuthConfig Limit
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
<Limit GET POST OPTIONS>
Order allow,deny
Allow from all
</Limit>
<LimitExcept GET POST OPTIONS>
Order deny,allow
Deny from all
</LimitExcept>
</Directory>
// httpd
# service httpd restart

Web osmond
Web
7.7

Web

//
$ whoami
osmond
//
$ cd
// public_html
$ mkdir public_html
// osmond
$ cd ..
$ chmod 711 osmond
// index.html

217

Red Hat Linux 9


$ cd ~/public_html/
$ vi index.html
// index.html
$ cat index.html
Osmond's Web Site.
// 7-5

7-5

Web

1 vi index.html
ftp DAV
2 URL
http://IP FQDN/~
IP 192.168.1.100 osmondURL
http://192.168.1.100/~osmond

7.4

WebDAV

218

WebDAV

7.4.1

Apache

www.huachu.cn

1
Apache 3
Order
Deny
Allow
1OrderOrder
Order Allow,Deny

Order Deny,Allow

Allow,Deny Deny,Allow

2Deny AllowDeny Allow

All
jamond.net
IP IP IP
/ 192.168.1.0/255.255.255.255.0
CIDR 192.168.1.0/24
2

7.8

//
# vi /etc/httpd/conf/httpd.conf
//#
<Location /server-info>
// mod_info
SetHandler server-info
// deny allow
Order deny,allow
// 192.168.1.77
Deny from all
Allow from 192.168.1.77

219

Red Hat Linux 9


</Location>
#
// httpd
# service httpd restart
//
// IP 192.168.1.77 7-6

7-6

// 7-7

7-7

220

Location
Directory Files

7.4.2

Apache

www.huachu.cn

1
1 RFC 2617
Basic
Digest

2 Directory
./htaccess 7-4
7-4 Apache

AuthName

AuthName

AuthType

AuthType Basic Digest

AuthGroupFile

AuthGroupFile

AuthUserFile

AuthUserFile

RequireRequire 7-5
7-5 Apache

Require user []

Require group []

Require valid-user

Apache
1
1

# htpasswd c

221

Red Hat Linux 9

# htpasswd

3
/etc/shadow

1
Web /var/www/
/etc/httpd/
2htpasswd

2Apache

7.4.3

7.9

//
# vi /etc/httpd/conf/httpd.conf
//
<Directory "/var/www/html/private">
//.htaccess
AllowOverride None
//
AuthType Basic
//
AuthName "jamond"
//
AuthUserFile /var/www/passwd/jamond
222

Apache

www.huachu.cn

//
require valid-user
</Directory>
#
//
# mkdir /var/www/passwd
# cd /var/www/passwd
# htpasswd -c jamond osmond
New password:
Re-type new password:
Adding password for user osmond
# htpasswd jamond jason
New password:
Re-type new password:
Adding password for user jason
#
// apache
# chown apache.apache jamond
#
// httpd
# service httpd restart
#
// 7-8

7-8

7-3

223

Red Hat Linux 9

Apache apache
apache apache

2.htaccess

7.10

.htaccess

//
# vi /etc/httpd/conf/httpd.conf
///var/www/html/private
<Directory "/var/www/html/private">
//.htaccess
AllowOverride AuthConfig
</Directory>
#
// httpd
# service httpd restart
// 7.8
///var/www/html/private .htaccess
# vi .htaccess
//
AuthType Basic
AuthName "jamond"
AuthUserFile /var/www/passwd/jamond
// osmond jason
require user osmond Jason
#
// 7-8

7.4.4

1
Directory Files Location
SatisfySatisfy
Satisfy

Satisfy all

224

Apache

www.huachu.cn

Satisfy any

Satisfy
2
Satisfy all
7.11

//
# vi /etc/httpd/conf/httpd.conf
//
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
// 192.168.1
Allow from 192.168.1
//
AuthType Basic
AuthName "Admin"
AuthUserFile /var/www/passwd/jamond
AuthGroupFile /var/www/passwd/admingrp
require group admin
Satisfy all
</Location>
#
//
# vi /var/www/passwd/admingrp
//
admin: osmond jason
# chown apache.apache /var/www/passwd/admingrp
#
// httpd
# service httpd restart
#
// 192.168.1 7-9

// 7-10
// 192.168.1 Admin

3
7.10 Satisfy all Satisfy any 192.168.1
admin

225

Red Hat Linux 9

7-9

7-10

7.4.5

WebDAV

1WebDAV
DAV WebDAV Web
FTP NFS
FTP NFS Web FTP NFS
WebDAV
HTTP WebDAV http://www.webdav.org
Apache WebDAV WebDAV

226

Apache

www.huachu.cn

2
HTTP HTTP
3 HTTP HTTP
GETPOST HEAD HTTP RPC 2616 HTTP
GETPOSTPUTDELETECONNECTOPTIONSTRACE
PATCHPROPFINDPROPPATCHMKCOLCOPYMOVELOCK UNLOCK
Apache HTTP <Limit><LimitExcept>
CGI

AuthType Basic
AuthName "Example"
AuthUserFile /var/www/passwd/jamond
AuthGroupFile /var/www/passwd/admingrp
<Limit POST>
require group admin
</Limit>

Apache WebDAV

3 WebDAV
Apache 2.0 WebDAV mod_dav
7.12

WebDAV

//
# vi /etc/httpd/conf/httpd.conf
//
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
// WebDAV
Dav On
//
AuthType Basic
AuthName "Admin"
AuthUserFile /var/www/passwd/jamond
AuthGroupFile /var/www/passwd/admingrp
// HTTP
<LimitExcept GET OPTIONS>
require group admin
</LimitExcept>
227

Red Hat Linux 9


</Directory>
#
// httpd
# service httpd restart
#
// apache
# chown -R apache.apache /var/www/html/
#

WebDAV apache apache


Apache

4 WebDAV
WebDAV Windows 2000 Web
WebDAV Windows FrontPage
DreamWeaver DAV
Windows 2000 Web

7-11

7-11

HTTP URL IP FQDN


7-12
228

Apache

www.huachu.cn

7-12

Admin 7-13

7-13

7-14 Web
Web

7-14

Web

Web

229

Red Hat Linux 9

7.5

7.5.1

Web

1
2
1 3
NFS

7.5.2

1
Apache
<Directory />
Options FollowSymLinks
</Directory>
<Directory "/var/www/html">
Options Indexes FollowSymLinks
</Directory>

ln s
230

7.13

Apache

www.huachu.cn

# cd /var/www/html
# ln -s /usr/share/doc doc
// 7-15

7-15

Apache Apache

2
Apache
error manual html
Directory

7.14

//
# vi /etc/httpd/conf/httpd.conf
//
Alias /ftp /var/ftp/pub
<Directory "/var/ftp/pub">
AllowOverride None
Options Indexes
Order allow,deny
231

Red Hat Linux 9


Allow from all
</Directory>
#
// apache 7-16

7-16

7.5.3

URL
URL
URL URL

1
Redirect
Redirect

[]

URL

[ URL]

7-6
7-6

301

URL URL URL


URL

302

URL URL URL

232

303

URL

410

URL

Apache

www.huachu.cn

URL

2
7-17

news

news/jun
jun old-news
news/jun URL old-news

7.15

7-17

//
# cd /var/www/html
# mkdir news old-news
# mkdir news/jun
# mkdir old-news/jun
# echo "Jun news">news/jun/index.html
# echo "Jun news (old)">old-news/jun/index.html
#
// 7-18

7-18

//
# vi /etc/httpd/conf/httpd.conf
//
Redirect 303 /news/jun http://192.168.1.100/old-news/jun
#
// httpd
# service httpd restart
// URL 7-19

233

Red Hat Linux 9

7-19

Apache

7.6

7.6.1

Web

Webalizer

1Web
ICP

Web

Web Web Web


Web

Web

234

Apache

www.huachu.cn

2
Apache 4



Cookie
Cookie Apache 2.0
Apache 2.0
3
Apache 4 7-7
7-7 Apache

ErrorLog

ErrorLog

LogLevel

LogLevel

LogFormat

LogFormat

CustomLog

CustomLog
CustomLog|

7.6.2

1Apache
ErrorLog logs/error_log
LogLevel warn

2
7-8
7-8

emerg

alert

crit

235

Red Hat Linux 9

error

emergalertcrit

warn

notice

errorwarn

info

debug

debug

warn 1 5
3

# cat /etc/httpd/logs/error_log
[Thu Jun 19 15:28:56 2003] [error] [client 192.168.1.77] Directory index forbidden by rule:
/var/ftp/pub/
[Thu Jun 19 17:16:24 2003] [notice] caught SIGTERM, shutting down
[Thu Jun 19 17:17:07 2003] [notice] Digest: done

7.6.3

1
Apache Apache
4 LogFormat
7-9
7-9

(common log format,CLF)

common

(referer log format)

referer

(agent log format)

agent

(combined log format)

combined

3 3

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined


CustomLog logs/access_log combined
236

Apache

www.huachu.cn

3
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
CustomLog logs/access_log common
CustomLog logs/referer_log referer
CustomLog logs/agent_log agent

2LogFormat
LogFormat LogFormat
7-10
7-10
192.168.1.77 - - [19/Jun/2003:23:03:33 +0800] "GET /manual/style/manual.css HTTP/1.1"
404 1203 "http://192.168.1.100/manual/logs.html" "Mozilla/4.0 (compatible; MSIE 6.0;
Windows NT 5.0)"
7-10 LogFormat

%h

IP

192.168.1.77

%l

identd

--

%u

--

%t

[19/Jun/2003:23:03:33 +0800]

%r

HTTP

GET /manual/style/manual.css HTTP/1.1

%>s

404

%b

HTTP 1203

%{Referer}i

http://192.168.1.100/manual/logs.html

%{User-Agent}i

Mozilla/4.0

(compatible;

MSIE

6.0;

Windows NT 5.0)

7.6.4

""
"\"GET /apache_pb.gif
HTTP/1.0"\"%r\"

1
Apache

237

Red Hat Linux 9

cd /etc/httpd/logs/
mv access_log access_log.old
mv error_log error_log.old
apachectl graceful

cron

3 logrotate
logrotate Linux
syslogdmail logrotate crond Red Hat Linux 9
Apache
7.16

logrotate

// logrotate crond
# grep logrotate /etc/cron.daily/logrotate
/usr/sbin/logrotate /etc/logrotate.conf
#
// logrotate
# cat /etc/logrotate.conf
//
weekly
//
rotate 4
//
create
///etc/logrotate.d
include /etc/logrotate.d
#
///etc/logrotate.d Apache
# cat /etc/logrotate.d/httpd
// var/log/httpd/ log
/var/log/httpd/*log {
//
missingok
//
notifempty

238

Apache

www.huachu.cn

//
sharedscripts
// Apache
postrotate
/bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` \
2> /dev/null || true
endscript
// postrotate endscript
}
#

4 Apache rotatelogs
Apache

Apache rotatelogs crond


rotatelogs

CustomLog logs/access_log combined

CustomLog "|/usr/sbin/rotatelogs

logs/access_log 86400" combined

8640086400 1
/etc/httpd/logs/access_log.nnnnnnnnnn nnnnnnnnnn
1970 1 1
86400

7.6.5

1Webalizer
Webalizer Webalizer
Web HTML
Web Internet Webalizer Web
Webalizer
C
200Mhz
Webalizer
10000 40M 15
Webalizer
Webalizer
wu-ftpd xferlog Squid

239

Red Hat Linux 9

UNIXLinuxNT OS/2 MacOS

2 Webalizer
Red Hat Linux 9 Webalizer RPM RPM
Webalizer Red Hat Webalizer

7.17

webalizer

// webalizer
# rpm -qa|grep webalizer
// Red Hat Linux 9 1
# mount /mnt/cdrom
// Red Hat/RPMS
# cd /mnt/cdrom/Red Hat/RPMS
// RPM
# rpm -ivh webalizer-2.01_10-11.i386.rpm
//
# cd;eject
//
# rpm -ql webalizer
// webalizer crond
/etc/cron.daily/00webalizer
/etc/webalizer.conf
/etc/webalizer.conf.sample
/usr/bin/webalizer
/usr/bin/webazolver
/usr/share/doc/webalizer-2.01_10
/usr/share/doc/webalizer-2.01_10/README
/usr/share/man/man1/webalizer.1.gz
/var/lib/webalizer
// HTML
/var/www/html/usage
/var/www/html/usage/msfree.png
/var/www/html/usage/webalizer.png
#

3 Webalizer
webalizer
webalizer /etc/webalizer.conf
webalizer
Red Hat Linux 9 webalizer
/etc/webalizer.conf man
240

Apache

www.huachu.cn

webalizer Apache
7.4
<Directory "/var/www/html/usage">
AuthType Basic
AuthName "Admin"
AuthUserFile /var/www/passwd/jamond
AuthGroupFile /var/www/passwd/admingrp
require group admin
</Directory>

Apache
7-20

7-20

webalizer

Jun 2003
241

You might also like