1

If this is possible it would save a lot of headaches. I would like to bind made up domains to localhost projects, if that is possible. I am on Ubuntu 20.10.

eoyath
  • 21
  • 2

2 Answers2

2

That's what /etc/hosts are for. Edit it and add your domains after localhost to end up like this:

127.0.0.1 localhost.localdomain localhost testing.test mysite.test

You'll need root rights for this (sudo). Next, you can ping them, open in your browser, etc. They will "resolve" locally to a 127.0.0.1. If you open them through your browser via domain name (assuming you have a local webserver on 127.0.0.1), it will send a correct Host attribute and you can configure your local webserver for virtual hosts same way like with any real domain (you can easily find a lot of manuals for this on the Internet for any particular web server software).

NStorm
  • 1,312
  • 7
  • 18
  • Sorry, I meant if I have different localhost projects on different ports, and I want to bind those localhost:port to a domain name, is that possible? I don't think it is with just hosts, as it just handles domain redirects, not binding to specific not 80 ports. – eoyath Feb 25 '21 at 17:40
  • You can configure a reverse proxy then for this. Where a VirtualHost for domain will proxy requests to a localhost:port. But it's kinda excessive thing. You can re-configure your webserver to use VirtualHosts instead of ports. – NStorm Feb 25 '21 at 17:44
0

Create DNS names in zones you control for each site or service.

thing1.example.net
thing2.example.net
thing3.test
thing4.contoso.com

Except with actual domains you have registered. Create AAAA and A records to service address of the things. Do not use loopback so other hosts can reach it.

Many choices in how to implement this. Your question is tagged nginx, so presumably http named based virtual hosts are an option. Wildcard DNS records pointing at the IP of a load balancer. One IP address per site, possibly using IPv6. A Kubernetes deployment that creates DNS names for every service. A DNS resolver on your laptop.

John Mahowald
  • 32,050
  • 2
  • 19
  • 34