Re: default site

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Eric Covener wrote:
On Tue, Jun 9, 2009 at 4:11 AM, Matus UHLAR - fantomas
<uhlar@xxxxxxxxxxx> wrote:
Boyle Owen wrote:
...
Amazing how this can get confused quickly, no ?
;-)
My version :

-- begin of main configuration file (say httpd.conf) ---

directives..
more directives...
...
Listen 80
...
NameVirtualHost *:80

# first Virtual Host
<VirtualHost *:80>
  ServerName whatever_you_want    # and doesn't matter, see below
  ....
  ....
</VirtualHost>

# 2d virtual host
<VirtualHost *:80>
  # the following name *must* be a real DNS name, resolving to the IP
  # address of this Apache server host
  ServerName server1.company1.com
  ....
  ....
</VirtualHost>

# 3d virtual host
<VirtualHost *:80>
  # the following name *must* be a real DNS name, resolving to the IP
  # address of this Apache server host
  ServerName server2.company1.com
  ....
  ....
</VirtualHost>

# 4th virtual host
<VirtualHost *:80>
  # the following name *must* be a real DNS name, resolving to the IP
  # address of this Apache server host
  ServerName server1.company2.com
  ....
  ....
</VirtualHost>

etc..
# nth virtual host
<VirtualHost *:80>
  # the following name *must* be a real DNS name, resolving to the IP
  # address of this Apache server host
  ServerName servern.companym.com
  ....
  ....
</VirtualHost>


Principles :

0) do not mix IP-based and name-based virtual hosts. That gets quite complicated, as you've seen before. So forget about the _default_ host. Pretend you've never heard about it.

1) whatever Directive is located in the "main" part of the configuration, acts as a default for all virtual hosts. That is, if a given <VirtualHost> section above does not re-define the same Directive, then it inherits it from the main configuration. But the main configuration is /not/ a host. It is just a "container" for these default directives.

2) When a request comes in to this server (and it will only come in if the DNS name points to this IP address), Apache tries to match the hostname indicated in the request, with each of the ServerName directives above, in the order in which the <VirtualHost> sections appear in the configuration.

3) If it succeeds (meaning there is a match), then Apache "adopts the personality" of that <VirtualHost> to process the request.
It's the same Apache process, no matter which personality it adopts.
But each personality comes with a different setup (the one composed of the default main directives, overridden by the ones in the selected <VirtualHost> section).

4) if it does not succeed (no match between the request hostname and a ServerName directive), then Apache adopts the personality of the *first* <VirtualHost> section above, no matter which "ServerName" that one contains. That is why basically the first ServerName does not matter (all that much), because anything Apache cannot match, will end up there.

5) Of course if you want requests to "127.0.0.1" and "localhost" (as a hostname in e.g. "http://localhost"; to be processed by a specific virtual host different from the default, then add a specific <VirtualHost> section as follows, *after* the first one :

<VirtualHost *:80>
  ServerName localhost
  ServerAlias 127.0.0.1
...
</VirtualHost>

thus 6) if you want one <VirtualHost> section to match more than one DNS hostname, then use ServerName for the first name, and ServerAlias for the other one(s).




---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
  "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx


[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux