Hopefully, you won't need to worry
about the
visible_hostname directive. However,
you'll need to set it if Squid
can't figure out the hostname of the machine on
which it is running. When this happens, Squid complains and refuses
to run:
% squid -Nd1
FATAL: Could not determine fully qualified hostname. Please set 'visible_hostname'
Squid wants to be sure about its hostname for a number of reasons:
The hostname appears in Squid's error messages. This
helps users identify the source of potential problems.
The hostname appears in the HTTP Via header of
cache misses that Squid forwards. When the request arrives at the
origin server, the Via header contains a list of
all proxies involved in the transaction. Squid also uses the
Via header to detect forwarding loops.
I'll talk about forwarding loops in Chapter 10.
Squid uses internal URLs for certain things, such as the icons for
FTP directory listings. When Squid generates an HTML page for an FTP
directory, it inserts embedded images for little icons that indicate
the type of each file in the directory. The icon URLs contain the
cache's hostname so that web browsers request them
directly from Squid.
Each HTTP reply from Squid includes an X-Cache
header. This isn't an official HTTP header. Rather,
it is an extension header that indicates if the response was a cache
hit or a cache miss. Since requests and responses may flow through
more than one cache, each X-Cache header includes
the name of the cache reporting hit or miss. Here's
a sample response that passed through two caches:
HTTP/1.0 200 OK
Date: Mon, 29 Sep 2003 22:57:23 GMT
Content-type: text/html
Content-length: 733
X-Cache: HIT from bo2.us.ircache.net
X-Cache: MISS from bo1.us.ircache.net
Squid tries to figure out the hostname automatically at startup.
First it calls the
gethostname( ) function,
which usually returns the correct hostname. Next, Squid attempts a
DNS lookup on the hostname with gethostbyname(
). This function typically returns both IP addresses and
the canonical name for the system. If
gethostbyname( ) succeeds, Squid uses the
canonical name in error messages, Via headers,
etc.Squid may be unable to determine its fully qualified hostname for a
number of reasons, including:
The hostname may not be set.
The hostname may be missing from the DNS zone or
/etc/hosts files.
The Squid system's DNS client configuration may be
incorrect or missing. On Unix, you should check the
/etc/resolv.conf and
/etc/host.conf files.
If you see the fatal message mentioned previously, you need either to
fix the hostname and DNS information or explicitly configure the
hostname for Squid. In most cases, it is sufficient to ensure the
hostname command returns a fully qualified
hostname and add an entry to /etc/hosts. If that
doesn't work, just set the visible hostname in
squid.conf:
visible_hostname squid.packet-pushers.net