localhost considered harmful (nginx ipv6 fun)
04 May 2013
After a recent update to one of my CentOS servers that hosts some django applications, I started getting 502’s with the following error message:
2013/05/05 10:06:04 [alert] 1771#0: *22 socket() failed (97: Address family not supported by protocol) while connecting to upstream, client: X.X.X.X, server: example.com, request: "GET /bid/ HTTP/1.1", upstream: "http://[::1]:8001/bid/", host: "example.com:81"
To make matters worse, I was only seeing this error message intermittently. I could refresh the page 10 times and only see this error 5/10 times.
Everything I found online said something about commenting out a line
like this one in your
listen [::]:80 default ipv6only=on;
However, I didn’t have such a line in any of my configs. Then I noticed the following snippet from the error message above:
and realized that
nginx (or, more likely, the system routing code)
::1 (which is
considered editing my
/etc/hosts file to remove the
::1 alias from
localhost but then settled on a cleaner solution: replacing all
localhost in my
nginx config files with
The moral of the story:
localhost might not mean what you think
it means! Don’t use
localhost unless you really support both
ipv6. Instead, use
blog comments powered by Disqus
- GitHub Profile
- Stack Overflow Careers Profile
- Stack Overflow Profile
- G+ Profile
- PGP Public Key
- Rafty -- Ripper and Friggin Transcoder, Y'all
- Make Readme Markdown
- Diffview Mode
- Indent Hints Mode
- Track That Thing
- Co-Founder & CEO of Directangular, LLC.
- Previously: Linux Kernel development for QuIC. Some of my work (a little stale) is available on the Code Aurora Forum, here, here, here, and here.
- My nerd hobby: Creating and contributing to a variety of Open Source projects. See my GitHub profile.