Professional Documents
Culture Documents
Lect 06 - Web Server (Apache) - LWL
Lect 06 - Web Server (Apache) - LWL
OVERVIEW
How Web Server Works
Apache Web Server
Virtual Hosting
User Authentication
DNS Server
Web Client
TCP connection
HTTP request
Web Client
HTTP response
Web Server
Web Client
APACHE MODULES
Modular architecture makes it possible f
or anyone to add new functions to the We
b server.
There are a large number of modules now
available for Apache.
It is easy to add a module to Apache.
CONFIGURING APACHE
Choosing functionality
Apache functionality is available through modules
which are either built in or loaded into the serv
er.
Apache is configured by placing directives in pla
in text configuration files.
Main configuration file is usually called httpd.c
onf
The location of this file is set at compile-time,
but may be overridden with the -f command line fl
ag.
Normal location of httpd.conf in Linux:
/etc/httpd/conf/httpd.conf
Web Server – Apache
Topic 04,p.13
©VTC 2012
Technical Support Fundamentals (ITP 4107)
SCOPE OF DIRECTIVES
Directives placed in the main configuration fi
le, httpd.conf, apply to the entire server.
To change the configuration for only a part of
the server, scope the directives by placing th
em in <Directory>, <DirectoryMatch>, <Files>,
<FilesMatch>, <Location>, and <LocationMatch>
sections or containers.
VirtualHost
BASIC CONFIGURATION
ServerRoot: The top of the directory tree under which
ServerRoot “/etc/httpd” the server's configuration, error, and log files are kept.
Listen 80
Load config files from the config directory
Include conf.d/*.conf "/etc/httpd/conf.d"
User apache The name (or #number) of the user/group to run httpd
Group apache as.
The directory out of which you will
DocumentRoot "/var/www/html" serve your documents
The name of the directory that is appended onto a
UserDir public_html
user's home directory if a ~user request is
DirectoryIndex index.html received.
Sets the file that Apache will serve if a directory
is requested.
ErrorLog logs/error_log
Sets the location of the error log file. In this
case, /etc/httpd/logs/error_log
APACHE: ADMINISTRATION
Use the chkconfig command to configure Apache to
start at boot:
chkconfig httpd on
APACHE LOGS
Two types of logs
True log – the server writes information t
o a designated file, adding sequent records
each time the information appears.
Status report – contains up-to-date status
reports on the server.
Requires the mod_info module.
Both are configured via the httpd.conf
file.
Access_log
Contains a record for each browser request,
which is a good way to see who have visited
your Web site.
Error_log
Records messages from the server about anyt
hing that goes wrong.
VIRTUAL HOSTING
Apache has the capability to serve many
different Web sites simultaneously.
This is called Virtual Hosting.
VIRTUAL HOSTS
Although the Web browser seems to be connecting to a
Web site that is an isolated entity, the website may
actually be hosted alongside many others on the same
machine.
ISPs do this a lot
Allowing additional Web presence without extra har
dware or software investment.
Each of the virtual server may have totally differen
t contents, configurations, and separate log files.
Alternative is to run another server on a different
port.
Part of the basic server configuration (httpd.conf).
USER AUTHENTICATION
We can password-protect content in both the ma
in and subdirectories of the DocumentRoot.
Apache allows for decentralized management of
the configuration via special files placed ins
ide the Web tree.
The special files are usually called .htaccess
, but any name can be specified in the AccessF
ileName directive (in httpd.conf)
Directives placed in .htaccess files apply to
the directory where the file is placed, and al
l the sub-directories.
.htpasswd File
To create the file, use the htpasswd utility program that came with
Apache. This is located in the bin directory of wherever you
installed Apache. To create the file, type:
htpasswd -c /etc/httpd/conf/.htpasswd rbowen
htpasswd will ask you for the password, and then ask you to type it
again to confirm:
# htpasswd -c /etc/httpd/conf/.htpasswd rbowen
New password: mypassword
Re-type new password: mypassword
Adding password for user rbowen
.htaccess File
The path to the password file
AuthUserFile /etc/httpd/conf/.htpasswd
Sets the name of a text file containing the
AuthGroupFile /dev/null list of user groups for authentication
AuthName "Restricted Files" Sets the realm name to be used
AuthType Basic Selects that method that is used to authenticate the user
require valid-user Setting the users allowed to access; will allow anyone
that is listed in the password file
In-place .htpaccess
The content of the .htaccess file can al
so be placed directly in the httpd.conf
file for the target directory as follows
:
DocumentRoot /var/chaiwanive/html
…..
<location />
AuthUserFile /etc/httpd/conf/.htpasswd
AuthName "Restricted Files"
AuthType Basic
require valid-user
</location>
Web Server – Apache
Topic 04,p.34
©VTC 2012
Technical Support Fundamentals (ITP 4107)
SUMMARY
Web server
Configuring Apache
Virtual Hosting
User Authentication