httpd-docs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Httpd Wiki] Update of "TroubleshootingVhosts" by SeanTimmins
Date Fri, 11 Jan 2013 19:28:29 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Httpd Wiki" for change notification.

The "TroubleshootingVhosts" page has been changed by SeanTimmins:
http://wiki.apache.org/httpd/TroubleshootingVhosts

New page:
= TroubleShooting Virtual Hosts =
The page will concentrate on Named Base virtual hosts mainly because it is what most people
use and it is the one most people seem to have problems with. Some things are 2.2 only and
are marked as such.

== The Basics ==
Virtual Hosts are much simpler than most people seem to think. This is not helped by some
unusual 'default' virtual hosts setups distributed by some of the major distributions.

First of all '''read the documentation'''!
 * http://httpd.apache.org/docs/current/vhosts/
 * http://httpd.apache.org/docs/current/vhosts/examples.html
 * ExampleVhosts

Secondly, and I can't stree this enough, '''USE''' "apachectl -S", "httpd -S" or "apache2ctl
-S" whenever you make any change to your configuration. It outputs various lines of information
that are vital to troubleshooting virtual host configuration.

== The Requirements ==
 * (2.2 only) You '''must''' have a [[http://httpd.apache.org/docs/current/mod/core.html#namevirtualhost|NamedVirtualHost]]
directive for each IP+port combination you wish to use, it should be IP:port or *:port

 {{{
 NameVirtualhost *:80
 }}}

 * Each [[http://httpd.apache.org/docs/current/vhosts/|<VirtualHost>]] directive should
have and IP:port inside it, in httpd 2.2 this should match your [[http://httpd.apache.org/docs/current/mod/core.html#namevirtualhost|NamedVirtualHost]]
directive

 {{{
 <VirtualHost *:80>
 }}}

 * Each virtual host '''must''' have its own unique [[http://httpd.apache.org/docs/current/mod/core.html#servername|ServerName]].
It is this that must match the host component of the URL that the user types into their browser.
If you define a second virtual host with the same server name then whichever virtual host
comes first in the configuration will be the only one that works with that name.

 {{{
 ServerName foo.com
 }}}
 * Each virtual host should also have its own distinct [[http://httpd.apache.org/docs/current/mod/core.html#documentroot|DocumentRoot]].
Although it is possible and in a few cases needed to share document roots, it is normally
better to use a single virtual hosts with server aliases.

 {{{
 DocumentRoot /var/www/foo
 }}}

== The First Virtual Host ==
With named base virtual hosts, the first one apache finds in the configuration files is special.
This is the one that requests will be passed to if apache has no way to determine which specific
virtual host to use. It is the '''default''' virtual host.

If the user types `http://my.domain.com/my/url/path` then it is the string `my.domain.com`
that is matched against the host component of the [[http://httpd.apache.org/docs/current/mod/core.html#servername|ServerName]]
or any [[http://httpd.apache.org/docs/current/mod/core.html#serveralias|ServerAlias]] (Remember
Server``Name can contain an optional schema and port)

''Advanced Note:'' It is actually the contents of the `Host` header that is used rather than
the host component of the URL. Though these would normally be the same.

== Virtual Host Example ==
{{{
NameVirtualHost 192.168.0.1:80

# any request to foo.com, or indeen anything other than bar.com that resolves
# to 192.160.0.1 will hit this first virtual host
<VirtualHost 192.168.0.1:80>
  ServerName foo.com
  ServerAlias www.foo.com
  DocumentRoot /var/www/foo
</Virtualhost>

# Only URLs that start http:///bar.com/ or http://www.bar.com will hit this
# virtual host
<VirtualHost 192.168.0.1:80>
  ServerName bar.com
  ServerAlias www.bar.com
  DocumentRoot /var/www/bar
</Virtualhost>
}}}

== Troubleshooting ==
The [[http://httpd.apache.org/docs/current/mod/core.html#errorlog|ErrorLog]] is always the
first place to look when you get any problems, but there are things you can do to make troubleshooting
virtual hosts easier.

 * Give each virtual host its own access and error log. this will enable you to easily separate
out requests to each virtual host and in particular verify a particular request is actually
hitting the virtual host you think it is. An alternative for determining the virtual host
a request hits is to add `%v` to the [[http://httpd.apache.org/docs/current/mod/mod_log_config.html#logformat|LogFormat]]

=== Log Files ===

---------------------------------------------------------------------
To unsubscribe, e-mail: docs-unsubscribe@httpd.apache.org
For additional commands, e-mail: docs-help@httpd.apache.org


Mime
View raw message