Professional Documents
Culture Documents
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
More
<VirtualHost 172.19.31.1>
ServerName www.company1.com
DocumentRoot /home/company1
</VirtualHost>
<VirtualHost 172.19.31.2>
ServerName www.company2.com
DocumentRoot /home/company2
</VirtualHost>
<VirtualHost 172.19.31.3>
ServerName www.company3.com
DocumentRoot /home/company3
</VirtualHost>
<VirtualHost 172.19.31.1:80>
ServerName www.company1.com
DocumentRoot /home/company1
</VirtualHost>
<VirtualHost 172.19.31.1:8080>
ServerName www.company2.com
DocumentRoot /home/company2
</VirtualHost>
Name-Based
If we want all of our servers
to share the same IP address,
there is only one major
difference required to the
apache server
we must add the directive
NameVirtualHost ipaddress to
our httpd.conf file where
ipaddress is the shared IP
address of all servers
this same address will be placed
in each servers <VirtualHost>
container
NameVirtualHost 172.19.31.1
<VirtualHost 172.19.31.1>
ServerName www.company1.com
DocumentRoot /home/company1
</VirtualHost>
<VirtualHost 172.19.31.1>
ServerName www.company2.com
DocumentRoot /company2
</VirtualHost>
<VirtualHost 172.19.31.1>
ServerName www.company3.com
DocumentRoot /home/company3
</VirtualHost>
More
<VirtualHost 172.19.31.1>
ServerName www.company1.com
ServerAlias company1.com
ServerAlias www.company1.org
ServerAlias www.company1.net
ServerAlias sales.company1.com
DocumentRoot /home/company1
</VirtualHost>
Or
<VirtualHost 172.19.31.1>
ServerName www.company1.com
ServerAlias company1.com
ServerAlias *.company1.com
ServerAlias www.company1.*
DocumentRoot /home/company1
</VirtualHost>
Continued
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 servers 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
More
<VirtualHost> Directives
AcceptPathInfo
AccessFileName (to override .htaccess as the default access file name)
DefaultType
<Directory>, <Files>, <Location>, <IfDefine>, <IfModule>, <Limit>
Include
Options, SetHandler
KeepAlive, KeepAliveTimeout, TimeOut, MaxKeepAliveRequests
ServerAdmin, ServerName, ServerSignature
ErrorDocument, ErrorLog, LogLevel (covered in chapter 7)
<Virtualhost 172.19.31.1>
ServerName www.company1.com
DocumentRoot /home/company1
<Directory /home/company1>
AllowOverride Indexes Options
</Directory>
</VirtualHost>
Example
NameVirtualHost 172.19.31.12
<Directory /var/www/hosts>
Order allow,deny
Deny from all
Establish protection for
</Directory>
directories above any
<VirtualHost 172.19.31.12>
virtual hosts directory
ServerName www.company1.com
DocumentRoot /var/www/hosts/company1
<Directory /var/www/hosts/company1> Override any directives and
protection from the previous
AllowOverride all
directory
Allow from all
</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>
Structure Continued
The httpd.conf file will store
Continued
Lets assume that dept1 will only permit specific users, then the
include file or .htaccess file for dept1 will need
LoadModule for the proper authentication
for the dept1 directory, authentication directives and a password file
(probably stored in that directory)
More