Top
Best
New

Posted by todsacerdoti 4/10/2025

.localhost Domains(inclouds.space)
302 points | 196 commentspage 5
EGreg 4/10/2025|
Wow! Today I learned that you can have subdomains of localhost. Never realized it!
jeroenhd 4/10/2025|
.localhost is in the same list as .example and .invalid when it comes to reserved names: https://datatracker.ietf.org/doc/html/rfc2606

It's a neat trick, but it comes with some caveats. For instance, `localhost` often resolves to both 127.0.0.1 and ::1, but `.localhost` is described in RFC2606 as "traditionally been statically defined in host DNS implementations as having an A record pointing to the loop back IP address and is reserved for such use". In other words, your server may be binding to ::1 but your browser may be resolving 127.0.0.1. I'm sure later RFCs rectify the lack of IPv6 addressing, but I wouldn't assume everyone has updated to support those.

Another neat trick to combine with .localhost is using 127.0.0.0/8. There's nothing preventing you from binding server/containers to 127.0.0.2, 127.1.2.3, or 127.254.254.1. Quite useful if you want to run multiple different web servers together.

EGreg 4/10/2025||
But is "foo.localhost" a valid domain name, for cookies and such?
jeroenhd 4/10/2025||
The RFC treats .localhost as a full TLD. I believe Windows does as well, as does Ubuntu (using default systemd-resolved), but macOS doesn't seem to resolve .localhost by default, necessitating the host file trickery.

Of course, in the early internet, the difference between a TLD and a host name weren't quite as clear as they are right now.

sebazzz 4/10/2025|||
> I believe Windows does as well

I cannot ping xyz.localhost because it doesn't resolve it.

EGreg 4/10/2025|||
We still need the Public Suffix List because of how inconsistent it was
vlod 4/10/2025||
Anyone care to shed why myapp.localhost:3000 (for the webapp I'm developing) is something that's useful for me rather than localhost:3000 ?

EDIT: on linux and don't use launchd, so I'd still the port number

jeroenhd 4/10/2025||
Using real domain names lets you experience the web as it is in production. Localhost has a bunch of exceptions (i.e. HTTP URLs are treated as secure, CORS acts funny, etc.). Using domain names disables special handling of localhost URLs that'll help you spot problems before they hit production.
ghoshbishakh 4/10/2025|||
Trick: edit yuor /etc/hosts file and add a domain name.

Self sign a certificate and add it to your trusted certificate list.

Or - use https://pinggy.io

vlod 4/10/2025|||
Thanks. This is the reason I wanted rather then convenience of not typing a port number (which I'd use a bookmark for, so I really don't care)
cyral 4/10/2025|||
Note the use of the Caddy webserver (you could also use nginx or whatever), which proxies to the port, so it's just myapp.localhost. I like this because it mirrors our production site. We can have subdomain.myapp.localhost and subdomain.myapp.com so links and everything work properly in both environments (assuming you have an env variable for the base domain)
oulipo 4/10/2025||
Could there be a way to setup the Caddy server dynamically using eg direnv so that it's only launched when I'm in my dev folder?
mrweasel 4/10/2025|||
Maybe you have a stack of applications that needs to communicate. Seeing db.localhost is a little easier to read that db:3360, but especially if you have multiple web applications. It's easier to read sso.localhost, api.localhost, and www.localhost.

They also show having the webserver to the TLS, that might be helpful.

csciutto 4/10/2025|||
The comparison is `myapp.localhost` vs `localhost:3000`. This is especially useful when you have web servers permanently running on your computer on ports, not just for momentaneous local development.
gwd 4/10/2025|||
It's `myapp.localhost` (without the port number). It's more useful because it's easier to allocate and remember a unique name than a unique port number.
tgpc 4/10/2025|||
maybe you're running a reverse proxy? it can direct you differently depending on how you refer to it
jbverschoor 4/10/2025||
Orbstack does all that pretty automatically. It also understands project structure / compose.

https://service.project.orb/

Tokumei-no-hito 4/10/2025|
broken link
jbverschoor 4/10/2025|||
Docs at https://docs.orbstack.dev/docker/domains

Forgot to add .local I see

jeroenhd 4/11/2025||
I hope Orbstack is also advertising those hostnames on mDNS, because using .local (or, seemingly worse, _relying_ on .local) will conflict with resolver logic on all kinds of devices.
jbverschoor 4/11/2025||
I'm not seeing any broadcasts.

What it does is it has a private network for the containers and itself (all containers get their own unique IP, so there's no port mapping needed).

http://orb.local simply lists all running containers.

The host-names are automatically derived from the containername / directoryname / compose project, but you can add other hostnames as well by adding docker labels.

It works really well.

zsoltkacsandi 4/10/2025|||
It was an example how OrbStack puts together the domain.
stuaxo 4/11/2025||
Nice, I've been wanting this - was just today talking about it.

Would be good to have the config all somewhere in my user's dir too.

Per user subdomains for their apps on localhost.

mholt 4/10/2025||
When using `.localhost` in the Caddyfile, you don't even need the `tls internal` line since that's assumed for that TLD.
donatj 4/10/2025||
We add a real actual DNS record for the local. subdomain pointing to 127.0.0.1

It works really well and means no setup on our developers machines

oulipo 4/10/2025|
Can you expand on this? you redirect *.local.example.com to 127.0.0.1, and then how do you setup the local machine so that eg myservice.local.example.com hits the correct port? I guess you still need a proxy somewhere? or you specify eg myservice.local.example.com:3000 ?
donatj 4/10/2025||
It's not a redirect. It's an actual A record on the domain for local.example.com -> 127.0.0.1

Then we just have an entry for local.example.com in our vhosts and bam everything works as expected. No need to mess with /etc/hosts

dd_xplore 4/11/2025||
Why do you need gzip when it's running locally and being accessed on the same system?
egberts1 4/13/2025||
I am old enough to remember

    localhost.localdomain
threatofrain 4/10/2025|
How do JS local dev setups use nice names like `local.drizzle.studio`?
Jnr 4/10/2025||
That is an external domain. Javascript on that site connects to the locally running drizzle service.
More comments...