3 ms·
Your computer has multiple network interfaces, and it has routing tables that tell it which interface to use for each IP it tries to talk to. E.g. your home rou
by pdpi 5y ago
Your computer has multiple network interfaces, and it has routing tables that tell it which interface to use for each IP it tries to talk to. E.g. your home router basically has one interface talking to the outside world and another talking to your local network, and its whole job is patching together connections through each of those interfaces.
Your personal computer will have ethernet and/or wifi, and those are entirely separate network interfaces, but it will also have a loopback interface (which is a dummy software-only interface that just connects back to your computer). The "localhost" hostname points at 127.0.0.1, and that IP is bound to the loopback interface, so all connections through localhost won't even hit the network, they'll just be looped back in (hence the name).
What all those -H/--host/--bind options do is tell your service which of those network interfaces to bind to. Instead of specifying an IP (and, therefore, an interface) to bind on, you can use 0.0.0.0 as a catch-all "meta-IP" that will tell your service to listen on all interfaces.
My personal preference (though it does require a bit more setup ahead of time) is to keep all these (HTTP) services listening on localhost, and then configure one single NGINX instance that binds on the external interface and proxies each individual service.
- 1vuio0pswjnm7 5y ago"The "localhost" hostname points at 127.0.0.1, but it will also have a loopback interface (which is a dummy software-only interface that just connects back to your computer)." AFAIK, 127.0.0.1 localhost as a HOSTS file entry is merely a convention. For example, the name "localhost" can point to any address in the 127.x.x.x address space or any address in general. Similarly, a loopback interface can be assigned any 127.x.x.x address. The convention is to assign 127.0.0.1. One of the nice things about NetBSD (IMO) is that when compiling one's own system, a loopback is not necessarily automatically created. It may be left up to the user to create one and assign it with an address. This can teach the user what software depends on the presence of a loopback interface that is assigned "127.0.0.1".
- pdpi 5y agoYeah, and you can also have multiple loopback interfaces in the 127.0.0.0/8 range if you want, no reason why you can only have one. That said, enough stuff out there assumes localhost = 127.0.0.1 = loopback interface that I wouldn't want to make my life complicated by breaking the convention. Also, that comment was already a bit muc, and I opted to simplify a bit.