Lighttpd Fails to Bind to Localhost

Page Trail: [[ Lighttpd Fails to Bind to Localhost ]]
2009-08-05 10:21
lighttpd logo

I installed the web server lighttpd on my laptop to test some configuration settings. As I didn't want to expose the server on the network, I uncommented server.bind = "localhost" from /etc/lighttpd/lighttpd.conf.

Then, restarting lighttpd failed with the following error:

(network.c.201)getaddrinfo failed:  Name or service not known ' localhost '

This is lighttpd 1.4.19-5 from main on Debian Lenny.

I was still able to ping localhost and checked my /etc/hosts file, but everything seemed fine. Finally, I checked the line of code the error points to (network.c line 201) and noticed it's part of an IPv6-specific chunk of code.

I found I could work around this issue by disabling IPv6 entirely in /etc/lighttpd/lighttpd.conf. For the uninitiated, comment out this line:

## Use ipv6 only if available.
include_shell "/usr/share/lighttpd/use-ipv6.pl"

Other Reports of This Issue

A couple reports of the same problem can be found on the old lighttpd forums, but no resolution was reached. Unfortunately, I can't reply there because those forums are now locked, and historical threads were not copied to lighttpd's new forums. The first report was from Debian's 1.4.19-1 package, and the second report does not identify the version.

A post on the debian-user-spanish list reports the same problem on Debian Lenny but received no replies.

That mailing list post does point to Debian bug 489063 (which doesn't come up on Google when you search for the error message). There, Pierre Habouzit, one of lighttpd's maintainers on Debian, suggests using server.bind = "::1" instead of server.bind = "localhost" when IPv6 is enabled. This will start up the server without errors, but then I can only access it as http://ip6-localhost/ (not http://localhost/).

Conclusion

This is a pretty annoying little issue, and it hasn't fully been resolved. At a minimum, this:

## bind to localhost only (default: all interfaces)
# server.bind                = "localhost"

should be:

## bind to localhost only (default: all interfaces)
## use ::1 when IPv6 is enabled or localhost for IPv4
## (see Debian bug #489063)
# server.bind                = "::1"
# server.bind                = "localhost"

That would at least point people in the right direction.

I've sunk enough time into this for now, though. I'll post an update here if I pursue this any further.