О КОПИРАЙТАХ |
Вся предоставленная на этом сервере информация собрана нами из разных источников. Если Вам кажется, что публикация каких-то документов нарушает чьи-либо авторские права, сообщите нам об этом. |
|
|
|
|
Apache HTTP Server Version 1.3
Virtual Host examples for common setups
Base configuration
Additional features
- Setup 1:
The server machine has two IP addresses (111.22.33.44
and 111.22.33.55)
which resolve to the names server.domain.tld and
www.otherdomain.tld respectively.
The hostname www.domain.tld is an alias (CNAME)
for server.domain.tld and will represent the
main server.
Server configuration:
...
Port 80
DocumentRoot /www/domain
ServerName www.domain.tld
<VirtualHost 111.22.33.55>
DocumentRoot /www/otherdomain
ServerName www.otherdomain.tld
...
</VirtualHost>
www.otherdomain.tld can only be reached through the
address 111.22.33.55, while www.domain.tld
can only be reached through 111.22.33.44
(which represents our main server).
- Setup 2:
Same as setup 1, but we don't want to have a dedicated main server.
Server configuration:
...
Port 80
ServerName server.domain.tld
<VirtualHost 111.22.33.44>
DocumentRoot /www/domain
ServerName www.domain.tld
...
</VirtualHost>
<VirtualHost 111.22.33.55>
DocumentRoot /www/otherdomain
ServerName www.otherdomain.tld
...
</VirtualHost>
The main server can never catch a request, because all IP addresses
of our machine are in use for IP-based virtual hosts
(only localhost requests can hit the main server).
- Setup 3:
The server machine has two IP addresses (111.22.33.44
and 111.22.33.55)
which resolve to the names server.domain.tld and
www-cache.domain.tld respectively.
The hostname www.domain.tld is an alias (CNAME)
for server.domain.tld and will represent the
main server.
www-cache.domain.tld will become our proxy-cache
listening on port 8080, while the web server itself uses the default
port 80.
Server configuration:
...
Port 80
Listen 111.22.33.44:80
Listen 111.22.33.55:8080
ServerName server.domain.tld
<VirtualHost 111.22.33.44:80>
DocumentRoot /www/domain
ServerName www.domain.tld
...
</VirtualHost>
<VirtualHost 111.22.33.55:8080>
ServerName www-cache.domain.tld
...
<Directory proxy:>
order deny,allow
deny from all
allow from 111.22.33
</Directory>
</VirtualHost>
The main server can never catch a request, because all IP addresses
(apart from localhost) of our machine are in use for IP-based
virtual hosts. The web server can only be reached on the first address
through port 80 and the proxy only on the second address through port 8080.
- Setup 1:
The server machine has one IP address (111.22.33.44)
which resolves to the name server.domain.tld.
There are two aliases (CNAMEs) www.domain.tld and
www.sub.domain.tld for the address 111.22.33.44.
Server configuration:
...
Port 80
ServerName server.domain.tld
NameVirtualHost 111.22.33.44
<VirtualHost 111.22.33.44>
DocumentRoot /www/domain
ServerName www.domain.tld
...
</VirtualHost>
<VirtualHost 111.22.33.44>
DocumentRoot /www/subdomain
ServerName www.sub.domain.tld
...
</VirtualHost>
Apart from localhost there are no unspecified
addresses/ports, therefore the main server only serves
localhost requests. Due to the fact
that www.domain.tld has the highest priority
it can be seen as the default or
primary server.
- Setup 2:
The server machine has two IP addresses (111.22.33.44
and 111.22.33.55)
which resolve to the names server1.domain.tld and
server2.domain.tld respectively.
The alias www.domain.tld should be used for the
main server which should also catch any unspecified addresses.
We want to use a virtual host for the alias
www.otherdomain.tld and one virtual host should
catch any request to hostnames of the form
*.sub.domain.tld with www.sub.domain.tld
as its server name. The address 111.22.33.55 should be
used for the virtual hosts.
Server configuration:
...
Port 80
ServerName www.domain.tld
DocumentRoot /www/domain
NameVirtualHost 111.22.33.55
<VirtualHost 111.22.33.55>
DocumentRoot /www/otherdomain
ServerName www.otherdomain.tld
...
</VirtualHost>
<VirtualHost 111.22.33.55>
DocumentRoot /www/subdomain
ServerName www.sub.domain.tld
ServerAlias *.sub.domain.tld
...
</VirtualHost>
Any request to an address other than 111.22.33.55
will be served from the main server. A request to
111.22.33.55 with an unknown or no Host:
header will be served from www.otherdomain.tld.
- Setup 1:
Catching every request to any unspecified IP address and port,
i.e. an address/port combination that is not used for any other
virtual host.
Server configuration:
...
<VirtualHost _default_:*>
DocumentRoot /www/default
...
</VirtualHost>
Using such a default vhost with a wildcard port effectively
prevents any request going to the main server.
A default vhost never serves a request that was sent to an
address/port that is used for name-based vhosts. If the request
contained an unknown or no Host: header it is
always served from the primary name-based vhost (the
vhost for that address/port appearing first in the configuration
file).
You can use
AliasMatch
or
RewriteRule
to rewrite any request to a single information page (or script).
- Setup 2:
Same as setup 1, but the server listens on several ports and
we want to use a second
_default_ vhost for port 80.
Server configuration:
...
<VirtualHost _default_:80>
DocumentRoot /www/default80
...
</VirtualHost>
<VirtualHost _default_:*>
DocumentRoot /www/default
...
</VirtualHost>
The default vhost for port 80 (which must appear before
any default vhost with a wildcard port) catches all requests that
were sent to an unspecified IP address. The main server is
never used to serve a request.
- Setup 3:
We want to have a default vhost for port 80, but no other default vhosts.
Server configuration:
...
<VirtualHost _default_:80>
DocumentRoot /www/default
...
</VirtualHost>
A request to an unspecified address on port 80 is served from the
default vhost any other request to an unspecified address and port
is served from the main server.
Apache HTTP Server Version 1.3
Index Home
|