0% found this document useful (0 votes)
31 views

CH5 WebServerConfiguration

The document discusses Apache web server including its history, compiling process, configuration file directives, performance tuning, and hosting virtual hosts. It explains how to configure name-based and IP-based virtual hosting to serve multiple websites from one server using different hostnames or IP addresses.

Uploaded by

Manoj Khatri
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

CH5 WebServerConfiguration

The document discusses Apache web server including its history, compiling process, configuration file directives, performance tuning, and hosting virtual hosts. It explains how to configure name-based and IP-based virtual hosting to serve multiple websites from one server using different hostnames or IP addresses.

Uploaded by

Manoj Khatri
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 22

Web Server (Apache httpd )

1
Apache Web Server
• A PAtCHy server: developed by the Apache group
• History-http://httpd.apache.org/ABOUT_APACHE.html
• First official public release (0.6.2) in April 1995
• Add adaptive pre-fork child processes (very
important!).
• Port to multiple platforms. Add documentation.
• Apache 1.0 was released on 12/1/95.

2
Compiling httpd-2.2.0
• Download httpd-2.2.0.tar.bz2 from http://www.apache.org/dist or
closer mirror sites
• $tar xjf httpd-2.2.0.tar.bz2
• $ ./configure --prefix=PREFIX
• $ make
• $ make install
• $ PREFIX/bin/apachectl start

• Here PREFIX is the prefix of the directory containing the distribution,


typically it is /usr/local/apache.
Since as a normal user, we donot have permission to install there, I
specify PREFIX as
/users/server/students/cs526/public_html/apache2.2m/htt
pd-2.2.0
• For configuring the apache with specific features, we can
specify the corresponding features as option to the
configure command. You can find the list of features by
“./configure –help”
• Here is the command we used to compile the htttpd with
proxy and cache modules we need. 3
Apache Exercises
• Each site.<exercise> directory contains
– conf: configuration files, httpd.conf, mime.types
– htdocs: contains web pages
– logs: access_log, error_log, httpd.pid
– cmd: alias of “<path>httpd -d
serverrootDirectory -X”
Here <path> specify the directory contains the
httpd program
-d specifies the server root directory, -X single
process execution

4
Httpd Configuration File
• Apache uses a set of directives to tell httpd
how the web site should be configured.
http://www.apache.org/docs/mod/directives.html
Each Apache configuration directive is described using a common format
that looks like this:

Syntax: directive-name some args


Default: directive-name default-value
Context: context-list
Override: override
Status: status
Module: module-name

Compatibility: compatibility notes


5
Block Directives
• Directives that limit the application of other
directives.
• Specify by a group like a tag section in html.
• <VirtualHost host[:port]>
...
</VirtualHost>
• <VirtualHost…><Directory dir>, <Files file>,
<Location URL> in ascending order of authority.
<Location> can overwrite others.
• dir, file, URL can specify using wildcards and full
regular expressions preceded by “~”
6
List of Directives
• User, Group: specify user and group that httpd runs on.
• ServerName: hostname of server
• ResourceConfig, AccessConfig: for reading additional
related directives. Can be disabled by /dev/null as value
• Listen: specify the port httpd run on (Port directive is
deprecated)
• ServerAdmin:email addr. for browser to do automatic
replies.
• DocumentRoot:
• TransferLog, ErrorLog, PidFile: where access,error logs,
httpd.pid should be located.

7
Performance Related Directives
• KeepAlive [on|off](on): keep connection alive for n requests
before terminate provided they come in before timeout. n is
defined in
MaxKeepAliveRequests <n>(100) directive
• KeepAliveTimeout <n>(15): wait for the next request for n
seconds before terminate the connections.
• Timeout <n>(300): max. time in sec for a block data.
• HostNameLookups [on|off|double](off): do reverse DNS lookup
for logging the domain name of the request.
• MaxClients <n>(256): the limit of # of simultaneous requests
(hence the # of child processes).
• MaxRequestsPerChild <n>(0): Spare(child) server dies after <n>
requests, avoid mem leak. 0 mean infinite requests.

8
Web Hosting
• There are a few way we can host a web site:
– Named-based Virtual Hosting
– IP-based Virtual Hosting
– Virtual Machine Virtual Hosting
• Name-based Virtual Hosting
– A set of hostnames shared the same IP address (similar to alias)
– utilize the HOST: meta header in http request (browser fill in the hostname) to
distinguish different web site.
– Each hostname will have its own site configuration, document root.
– Require either the set of hostnames are registered DNS names or the client
machines need to configure their ip addresses mapping in hostfiles such as
/etc/hosts (Unix) or C:\WINDOWS\system32\drivers\etc\hosts
(Windows)
• IP-based virtual Hosting:
– Require a unique IP address for each virtual hosting site
– Use IP alieas to configure the same Network Interface Card (NIC) to listen to
different IP address, e.g., ifconfig eth0:1 128.198.160.33
– Some Unix system sets limit on how many IP aliases can be supported.
• Use <VirtualHost hostname[:port]> block directives
• Specify ServerAdmin, DocumentRoot, ServerName, ErrorLog, TransferLog
for individual VH

9
Virtual Hosts
• The apache server can handle multiple “web sites” at a time
– a web service provider company may have multiple different
sites to offer (see figure 6-2)
– a single company may wish to partition their web site into
multiple domains (e.g., sales, accounting, management,
research, etc) (see figure 6-1)
– a single organization may wish to give each user their own web
site
• In any of these cases, the idea is to have the web server
create several virtual hosts
– although in the last case, we just divide the file space up
• We use the <VirtualHost> container for this, which allows
each “host” to have their own server-specific configuration
– we can divide our hosts up based on IP addresses or IP aliases
– the container looks like this: <VirtualHost ipaddress>
ServerName ipalias
DocumentRoot path
10
</VirtualHost>
IP-Based
• Assume that we want each of our servers to have a
unique IP address
– in fact, we will have to set up the DNS entries so that all
of the different IP addresses resolve to the same IP
address, that of our web server
• see figure 6-3
• Now we place in our httpd.conf file <VirtualHost>
containers for each server
– one container per server
– this allows us to add more servers over time (or remove
servers) just by modifying the httpd.conf file
• each virtual host will apply the overall server configuration but
you can also specify server-specific directives for each virtual
host as is needed
• many of the directives we saw from chapter 5 that dealt with 1
server can be applied to any, each or some combination of
servers 11
• Each <VirtualHost> container
will have its own unique IP More
address <VirtualHost 172.19.31.1>
ServerName www.company1.com
• To the right, you see three DocumentRoot /home/company1
different servers </VirtualHost>
<VirtualHost 172.19.31.2>
• Notice how each server maps ServerName www.company2.com
to a different location under DocumentRoot /home/company2
DocumentRoot </VirtualHost>
<VirtualHost 172.19.31.3>
• We might create symbolic ServerName www.company3.com
links so that each company DocumentRoot /home/company3
</VirtualHost>
can edit their own directory
from a location that they are <VirtualHost 172.19.31.1:80>
more familiar with ServerName www.company1.com
DocumentRoot /home/company1
• We can also set up our </VirtualHost>
various servers to respond to <VirtualHost 172.19.31.1:8080>
different ports of the same IP ServerName www.company2.com
DocumentRoot /home/company2
address (see the right below) </VirtualHost> 12
Name-Based
• If we want all of our servers
to share the same IP NameVirtualHost 172.19.31.1
address, there is only one <VirtualHost 172.19.31.1>
major difference required to ServerName www.company1.com
the apache server DocumentRoot /home/company1
</VirtualHost>
– we must add the directive <VirtualHost 172.19.31.1>
NameVirtualHost ipaddress to ServerName www.company2.com
our httpd.conf file where DocumentRoot /company2
ipaddress is the shared IP </VirtualHost>
address of all servers <VirtualHost 172.19.31.1>
ServerName www.company3.com
• this same address will be placed
DocumentRoot /home/company3
in each server’s <VirtualHost> </VirtualHost>
container
• We will also have to ensure
that all DNS servers resolve
any of the servers’ aliases to
this same address 13
• We can use the name-based
approach to allow multiple alias More
names to map to the same server
by supplying numerous <VirtualHost 172.19.31.1>
ServerAlias directives within a ServerName www.company1.com
VirtualHost container ServerAlias company1.com
– for instance, imagine that ServerAlias www.company1.org
www.company1.com wishes to ServerAlias www.company1.net
also be recognized by ServerAlias sales.company1.com
company1.com, DocumentRoot /home/company1
www.company1.org, </VirtualHost>
www.company1.net and
sales.company1.com Or
• We can also permit the * or ? <VirtualHost 172.19.31.1>
ServerName www.company1.com
wildcard to save on the number ServerAlias company1.com
of entries we might want to put ServerAlias *.company1.com
into our container ServerAlias www.company1.*
– however, this can easily result in DocumentRoot /home/company1
problems with respect to have </VirtualHost>
misspelled server names map to
the wrong thing
14
Some Additional Comments
• If we just add the previous entries into our httpd.conf file,
it does us no good unless we also ensure that DNS entries
have the same mappings
– for instance, if you are at site X and issue an http request for
www.company1.org, if the DNS for site X does not map
www.company1.org to 172.19.31.1, then the http request
never makes it to our server for processing!
– so we have to make sure that the DNS tables across the
Internet reflect the proper mappings
• we have already set up a BIND server, so we will explore this in the
next labs
• You can use both IP-based and Name-based virtual hosts
if desired by having some VirtualHosts share the same IP
address and others have different addresses
– this will require that you use NameVirtualHost for any shared
address 15
Continued
• If you are using name-based virtual hosts, then any
http request that reaches your server will already
have had the IP address resolved
– because of this, we do not have to put IP addresses in our
VirtualHost containers, but can replace them with *
• the * will match any IP address
• only do this with the name-based approach, if you use the IP-
based approach, then each virtual host maps to a unique
address
• If your computer has multiple IP addresses (e.g., an
internal address and an external address)
– you can place all IP addresses in the VirtualHost
container (and the NameVirtualHost directive)
• NameVirtualHost 172.19.31.12
• NameVirtualHost 10.11.31.12
• <VirtualHost 172.19.31.12 10.11.31.12> … </VirtualHost> 16
Include Files
• Recall that not all directives need to be placed in
the httpd.conf file
– in fact, for virtual hosts, you would not want this
because each server’s web administrator(s) will need
to edit the configuration file for that server
• if all directives were shared in one file, then you would
have to give many different people access to that one file

– therefore, we allow the administrators to place


these server-wide directives in a different file, which
is then included with the httpd.conf directives via
include directives
17
Overriding httpd.conf Directives
• Recall that the outermost context is the server’s settings
– we do not want our individual administrators to have access to
httpd.conf but we want to allow them to have their own specific
directives in their include files
– so, in our httpd.conf file, we need to add the AllowOverride
directive to any DocumentRoot directory
• for instance, in the <VirtualHost> container for company1, you will add
<Directory /home/company1> and place the AllowOverride All directive in
that container
– the question is, do we want to use “All” in our AllowOverride or be
more specific?
• AllowOverride can have None, <Virtualhost 172.19.31.1>
All, or any subset of this list: ServerName www.company1.com
– AuthConfig, FileInfo, Indexes, DocumentRoot /home/company1
Limit, Options <Directory /home/company1>
• see the example to the right AllowOverride Indexes Options
</Directory>
</VirtualHost> 18
NameVirtualHost 172.19.31.12
<Directory /var/www/hosts> Example
Order allow,deny
Deny from all
</Directory> Establish protection for
<VirtualHost 172.19.31.12> directories above any
ServerName www.company1.com virtual host’s directory
DocumentRoot /var/www/hosts/company1
<Directory /var/www/hosts/company1> Override any directives and
AllowOverride all protection from the previous
Allow from all directory
</Directory>
</VirtualHost>
<VirtualHost 172.19.31.12>
ServerName www.company2.com
DocumentRoot /var/www/hosts/company2
<Directory /var/www/hosts/company2>
AllowOverride all
Allow from all
</Directory>
</VirtualHost> 19
Web Site Structure

20
Virtual Host Performance and Status
• The only real drawback to using virtual hosts is that
the more hosts you have, the worse the server’s
performance will be
– running 10 servers instead of 1 will probably result in 10
times the number of requests to service and thus the
server will be 10 times more busy
– running 10 servers instead of 1 will probably require 10
times the amount of disk usage
• an ISP that wishes to provide web server services will have to
take this into account when purchasing server hardware
• To determine the status of the various servers, use
httpd –S which will list
– IP address and port (if different from the default server)
– name of the server
– location of DocumentRoot for the given server
• we will examine status information in more detail in chapter 721
Remember
• Basic Configurations
• Virtual Hosting & its Types

22

You might also like