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?action=diff&rev1=2&rev2=3

Comment:
Tiday up and minor rewording

  This page is not linked anywhere yet. I was going to have it linked to my 
personal home page until I was informed they were not suitable for the wiki. 
I'll join the documentation project mailing list and the wiki changes list and 
then update/delete this page as necessary.
  
  = 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 many people seem to have problems with. 
Some things are httpd 2.2 or 2.4 only and are marked as such.
+ The page will concentrate on Name Based virtual hosts mainly because it is 
what most people use and it is the one many people seem to have problems with. 
Some things are httpd 2.2 or 2.4 only and are marked as such.
  
  == The Basics ==
- Virtual Hosts are much simpler than most people seem to think. Thing are made 
more complicated by some unusual 'default' virtual host setups installed by 
some of the major distributions.
+ Virtual Hosts are much simpler than most people seem to think but in some 
cases are made more complicated by some unusual 'default' virtual host setups 
installed by some of the major distributions.
  
  First things first, '''read the documentation'''!
  
@@ -14, +14 @@

   * http://httpd.apache.org/docs/current/vhosts/examples.html
   * ExampleVhosts
  
- Secondly, and I can't stress this enough, use `apachectl -S` or `httpd -S` 
whenever you make any change to your configuration. It outputs various lines of 
information that are vital to the troubleshooting of virtual host 
configuration. See below for further information.
+ Secondly, and I can't stress this enough, use `apachectl -S` or `httpd -S` 
whenever you make any change to your configuration. It outputs various lines of 
information that are vital to the troubleshooting of virtual host 
configuration. See [[#apachectl|below]] for further information.
  
- Thirdly, althought there are a couple of exceptions, if you have defined an 
access log then httpd will ''always'' log something to it when it serves a 
request and an entry will always be logged in the error log on a 4xx or 5xx 
return code. If you cannot find the access/error log entry then you are either 
looking in the wrong log or the request never hit your web server.
+ Thirdly, althought there are a couple of exceptions, if you have defined an 
access log then httpd will ''always'' log something to it when it serves a 
request and an entry will always be logged in the error log on a 4xx or 5xx 
return code. If you cannot find the access/error log entry then you are either 
looking in the wrong log or the request never actually reached your web server.
  
  == Virtual Host Requirements ==
   * (httpd 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 and should come before any of your actual virtual hosts.
@@ -24, +24 @@

   NameVirtualhost *:80
   }}}
  
-  * Each [[http://httpd.apache.org/docs/current/vhosts/|<VirtualHost>]] 
directive should have an IP:port inside it, in httpd 2.2 this should match your 
[[http://httpd.apache.org/docs/current/mod/core.html#namevirtualhost|NamedVirtualHost]]
 directive
+  * Each [[http://httpd.apache.org/docs/current/vhosts/|<VirtualHost>]] 
directive should have an IP:port inside it, in httpd 2.2 this should match your 
[[http://httpd.apache.org/docs/current/mod/core.html#namevirtualhost|NamedVirtualHost]]
 directive. Unless you know exactly what you are doing, do not mix IP:port and 
*:port as the results may be unpredictable.
   {{{
   <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.
+  * 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 another virtual host with the same server 
name (or server alias) then whichever virtual host comes first in the 
configuration will be the only one that works with that name.
   {{{
   ServerName foo.com
   }}}
@@ -40, +40 @@

   }}}
  
  == 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.
+ 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.
  
- In general, if the user types `http://my.domain.com/my/url/path` into their 
browser, 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).
+ In general, if the user types `http://my.domain.com/my/url/path` into their 
browser, 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]] 
directive (Remember Server``Name can contain an optional schema and port). 
Anything that does not match a Server``Name or Server``Alias in your 
configuration will be served by the default virtual host.
  
- Anything that does not match a ServerName or ServerAlias in one of your 
virtual hosts will be served by the default.
- 
- ''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.
+ ''Note:'' It is actually the contents of the `Host` header that is actually 
used by httpd here rather than the host component of the URL, though these 
would normally be the same.
  
  == Virtual Host Example ==
  
- Here is a very simple 2 virtual hosts example that we will use to highlight 
the output of `apachectl -S`.
+ Here is a very simple two virtual host example that we will use to highlight 
the output of `apachectl -S`.
  {{{
  # NameVirtualhost is needed in httpd 2.2 only
  NameVirtualHost 192.168.0.1:80
  
  # Any request to foo.com, or indeed anything other than bar.com that resolves
- # to 192.168.0.1 will hit this first virtual host
+ # to 192.168.0.1 will be served by 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
+ # Only URLs that start http:///bar.com/ or http://www.bar.com will be served
- # virtual host
+ # by this virtual host
  <VirtualHost 192.168.0.1:80>
    ServerName bar.com
    ServerAlias www.bar.com
    DocumentRoot /var/www/bar
  </Virtualhost>
  }}}
+ 
  == Problem Solving Tips ==
+ 
  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 should be. 
An alternative for determining the virtual host a request hits is to add `%v` 
to the relevant 
[[http://httpd.apache.org/docs/current/mod/mod_log_config.html#logformat|LogFormat]].
+  * 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 
that a particular request is actually being served by the virtual host you 
think it should be. An alternative for determining the virtual host a request 
is served by is to add `%v` to the relevant 
[[http://httpd.apache.org/docs/current/mod/mod_log_config.html#logformat|LogFormat]].
  
-  * Use a command line tool to access your virtual host. This is particularly 
useful when you have redirects in place and wish to make sure they are working 
correctly. Commonly used tools for the troubleshooting of httpd from the 
command line are [[http://curl.haxx.se|curl]] and 
[[http://www.gnu.org/software/wget/|wget]]. If you have the perl LWP module 
installed you can use lwp-request (often linked as GET). It is worth 
familiarising yourself with these tools and their options.
+  * Use a command line tool to access your virtual host. This is particularly 
useful when you have redirects in place and wish to make sure they are working 
correctly. Commonly used tools for the troubleshooting of a web server from the 
command line are [[http://curl.haxx.se|curl]] and 
[[http://www.gnu.org/software/wget/|wget]]. If you have the perl LWP module 
installed you can use lwp-request (often usable as `GET`). It is worth 
familiarising yourself with these tools and their options, but here are some 
examples by way of an introduction.
  
   {{{
+  # Get the headers from foo.com. Output in the file headers.txt
-  # Get the headers from foo.com
-  # Output in the file headers.txt
   curl -s -D headers.txt -o /dev/null http://foo.com/
   GET -uUsSed http://foo.com/ > headers.txt
  
-  # Using just the host header instead of the fqdn
+  # Using just the host header instead of the fqdn. Output in the file 
headers.txt
-  # Output in the file headers.txt
   curl -H "Host: foo.com" -s -D headers.txt -o /dev/null http://192.168.0.1/
   wget --header="Host: foo.com" -nv --save-headers=on -O headers.txt 
http://192.168.0.1/
   GET -H "Host: foo.com" -uUsSed http://192.168.0.1/ > headers.txt
  
-  # Get headers and content to terminal
+  # Get the headers and content of the page to the terminal
   curl -s -i http://foo.com/
   wget -nv --save-headers=on -O - http://foo.com/
   GET -uUsSe http://foo.com/
   }}}
  
-  * ''Every'' time you modify your configuration you should be running 
`apachectl -S` to test it before you restart your web server. Below are two 
examples of the output from this command for httpd 2.2 and 2.4 when using the 
example virtual host configuration above, with a line by line explanation after 
each.
+ <<Anchor(apachectl)>>
+  * ''Every'' time you modify your configuration you should be running 
`apachectl -S` to test it before you restart your web server. Below are two 
examples of the output from this command for httpd 2.2 and 2.4, with line 
numbers added for clarity, with a line by line explanation of each. The output 
was generate using a simple httpd install with the example virtual host 
configuration above.
+ 
   {{{
   # Example output from httpd 2.2
   1: VirtualHost configuration:
@@ -147, +147 @@

  <<BR>>
   In the ouput, if you see any duplicate server names or aliases (other than 
the default one and the namevhost immediately after it) then you have virtual 
hosts with duplicate names and only the first one in the list will work.
  
-  If with httpd 2.2 you do not have a Name``Virtual``Host directive you will 
not see the line ending in `is a NameVirtualHost` and depending on your exact 
configuration you may see something similar to one of the following warnings:
+  With httpd 2.2, if you do not have a Name``Virtual``Host directive you will 
not see the line ending in `is a NameVirtualHost` and depending on your exact 
configuration you may see something similar to one of the following warnings:
  
   {{{
   # If your virtual hosts are defined with IP:port
  [Fri Jan 11 22:27:30 2013] [warn] VirtualHost 192.168.0.1:80 overlaps with 
VirtualHost 192.168.0.1:80, the first has precedence, perhaps you need a 
NameVirtualHost directive
+ 
   # If your virtual hosts are defined with *:port
  [Fri Jan 11 22:28:04 2013] [warn] _default_ VirtualHost overlap on port 80, 
the first has precedence
   }}}

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

Reply via email to