Alternate name for localhost not working
I tried using an alternate name for localhost.
127.0.0.1 localhost test.dev
This doesn't show apache2 page when I use test.dev but works when I type localhost.
Also I tired using
127.0.0.1 localhost test
This worked with http but not with https, can anyone help?
If you are working locally, you most certainly can point any domain to your localhost within /etc/hosts
. I do this all the time for development. What you will want to do, however, is put each domain on its own line.
For example, your /etc/hosts
file might look something like this:
127.0.0.1 localhost
127.0.0.1 test.dev
127.0.0.1 another.dev
127.0.0.1 yet.another.dev
The .dev
addresses above would all be handled by the local web server.
Where this can fall down, though, is when you're using a browser that wants to use its own DNS mechanisms. When this happens, it doesn't matter what you have in /etc/hosts
, because the browser will ask an external DNS provider directly and cache the result.
If you would like to avoid TLDs that exist, note that .app
is a valid TLD as per Wikipedia, and .devel
is certainly free to use. I generally stick to .local
for things on my local machine, .vbox
for VirtualBox resources, and .{environment}
when testing against specific environments (Docker, EC2, etc.). That said, there is nothing stopping you from using a .com
in /etc/hosts
if you choose ... aside from your browser.