Name Resolution: Why nginx Can't Find the API
Arjun pointed nginx at a hostname so the API can move later, and every store app started failing. Follow the name through the resolver, fix the record, and learn why fixing it was not enough.
- Beginner
- 36 min
- Networking
- DNS
- nginx
- Kestrel
Overview
Arjun had a good idea: instead of 127.0.0.1:8000, nginx should forward to a name, orders.kestrel.internal, so the API can move to its own machine next month with a one-line change. He added the name to /etc/hosts, reloaded nginx and went home.
This morning Harpreet Kaur, head of operations, reports that every store app shows "Something went wrong". nginx answers 502 Bad Gateway to everything.
In this lab you will learn how a Linux machine really turns a name into an address — not "DNS", but a chain of sources in a fixed order — follow the broken name to its bad record, fix it, and meet the cache that makes "I fixed DNS but nothing changed" the most common sentence in operations.
What you will learn
- Read the resolver chain from
/etc/nsswitch.confand/etc/resolv.conf - Ask the resolver the way programs do, with
getent hosts - Trace a 502 from nginx's error log to the record that caused it
- Fix an
/etc/hostsentry in place, and know why the first match wins - Make nginx resolve its upstream again, and verify end to end
Before you start
- Addresses & Sockets first is helpful, but not required
- You can edit a file with
nanoand run commands withsudo
Tasks
- 01How this machine turns a name into an address
- 02Follow the name nginx is using
- 03Correct the record
- 04Make nginx look again