Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Everybody loves their random port numbers these days, but I still prefer custom hostnames.

Just chuck an entry into your hosts file and tell your web server to sniff for it and you’re done. Run your stuff on port 80 like nature intended and never have to teach either end of your app how to deal with colons and numbers in domain names.

And you get to skip the six paragraphs of pain the other commenters are describing, orchestrating their kubernetes and whatnot.

e.g.: http://dev.whatever/



I like to combine both locally — bind to port 0 to get an arbitrary unprivileged port, and use domains in /etc/hosts for easier configuration ;-)

For those not familiar with what you are talking about, you can add things like the following to your /etc/hosts file:

  127.0.1.1  foo.local
  127.0.2.4  foo.bar.local
  ...
They will all resolve to local host, so make sure to bind your services to those IP addresses (eg. `nc -l 127.0.2.4 80` will bind only to 127.0.2.4 on port 80).

But running on unprivileged ports like 80 means you've got to run the server as root.


At least on macOS you don't even need to add to /etc/hosts, just use .localhost as the TLD.


How does that work with binding the same port to it? Does it automatically assign a new IP to every new domain resolv() call gets (and then caches it)?


This is the right answer. But use the .test domain as this is meant for the usecase.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: