localhost: definition and meaning

localhost is the reserved hostname for the machine you are on. Name resolution is expected to map it to a loopback address, usually 127.0.0.1 for IPv4 and ::1 for IPv6, so connections to it stay on your own computer.

Updated

localhost is a hostname, not an address. It is reserved to mean this machine: whichever computer you are typing the URL on. When a program connects to localhost, the name is resolved to a loopback address, and the traffic is meant to stay on the host.

How the name resolves

RFC 6761 reserves localhost as a special-use domain name. It tells users they may assume that IPv4 and IPv6 address queries for it resolve to the respective loopback address, and it asks name resolution libraries to return that address. So an IPv4 query gives a loopback address in the 127.0.0.0/8 block, usually 127.0.0.1, and an IPv6 query gives ::1. That is why one name can map to two addresses. The name is the part you type. The loopback address is the IP-level destination the operating system uses.

The same RFC section covers every name under .localhost, so app.localhost is meant to resolve to loopback too. The RFC asks resolvers to do this with “SHOULD”, not “MUST”, so do not assume every resolver does.

Same name, three connections

Terminal
curl http://localhost:3000/
curl http://127.0.0.1:3000/
curl "http://[::1]:3000/"

The second command connects to an IPv4 loopback address directly. The third connects to the IPv6 one, and RFC 3986 requires square brackets around an IPv6 address in a URL. The first goes through name resolution, so the client may end up on either address, depending on its resolver and its own rules.

A common confusion

“It works on 127.0.0.1 but not on localhost” can mean the server listens on one address family only. A server bound to 127.0.0.1 does not accept connections to ::1, because they are different addresses. A client that tries ::1 first may fail or fall back, depending on how it is written.

Separately, using localhost in a URL says where the client connects, not who may connect. What decides that is the address the server binds to. A server bound to a loopback address accepts connections only from the same machine. One bound to 0.0.0.0 listens on all local IPv4 interfaces, as ip(7) describes.

The Secure Contexts specification treats loopback addresses (127.0.0.0/8 and ::1) as potentially trustworthy origins, so a page served from one can count as a secure context over plain HTTP. It treats localhost names the same way only when the browser follows the localhost name resolution rules, which make them resolve to loopback. Test secure-context features in each browser you target.

In Rig

  • Local HTTPS names: Rig gives a project a name under .localhost: {slug}.rig.localhost, where the slug is the project name in lowercase letters, digits, and hyphens, up to 40 characters. A project that already has a *.localhost HTTPS address keeps it. A TLS proxy serves the name on port 8443 by default (the port cannot go below 1024) and forwards to the project’s plain HTTP address. The proxy listens on 127.0.0.1 and, when it can, on ::1, and it only fronts loopback upstreams.
  • Certificate: Rig creates it with mkcert, and on a Mac it tries to install mkcert through Homebrew when it is missing. The certificate covers the project’s host name, *.rig.localhost, localhost, 127.0.0.1, and ::1. Without mkcert, Rig falls back to a self-signed certificate made with openssl, and browsers warn about that one.
  • Health checks: when a project’s URL uses localhost, Rig probes 127.0.0.1 first, then the URL as written.

Sources

  1. RFC 6761: Special-use domain namesOfficial documentation, checked 13 October 2026
  2. RFC 3986: URI generic syntaxOfficial documentation, checked 13 October 2026
  3. W3C: Secure contextsOfficial documentation, checked 13 October 2026
  4. Linux man page: ip(7)Official documentation, checked 13 October 2026
  5. Rig documentation: Local HTTPS (names, certificates, and health probes confirmed in Rig’s source code)Rig source code, checked 13 October 2026

See how Rig fits in

Rig is a Mac app that starts, stops, and watches the processes in a project from one window. The knowledge base explains each part in plain language.

Related

https://userig.app/glossary/localhost