I recently tried to add a URL in my /etc/hosts file, and because of many different attempts in the past, I realized I most probably have some extra lines in there which are not necessary.

I have read different information on the web and tried different syntax in the hosts file to finally have the 2 websites show at the correct URLs.

This is not for local development.

That was a few weeks ago. Here is what is looks like after my last failed attempt, I had to put it back to how it was :       localhost
::1             localhost ip6-localhost ip6-loopback
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters servername.website-one.com servername.another-site.com servername.website-one.com servername.site-two.com servername.another-site.com servername servername.site-two.com site-two.com servername servername.website-one.com website-one.com servername servername.another-site.com servername.another-site.com test.website-one.com website-one.com site-two.com another-site.com

Today I tried to add a 3rd website, and for some reason the 2 sites are being redirected to that one site. The problem is that this "redirection" (technically I don't think it should be called like a redirection). I am confused because there are various 'factors', or various files, that could have that effect.

As far as I understood, here is the list of "factors" that I should take into account for my problem :

  • the /etc/hosts file on the server ( apache2, ubuntu 16.04 )
  • my DNS setting within my domain registrar account
  • the configuration files for each site ( I know it can be specified individually with multiple sites in there "sites-available" and "sites-enabled" directories, or generally in one global file, but I can't remember which is the global file for all sites and where it is located

I also tried to use a sub domain test.website-one.com without any success.

My hosts file is a mess. I remember reading somewhere that the server name should be used and it can be on one line, and then I red something else elsewhere.

  • I suspect you are having name+Apache configuration issues... the new website points to the other vhosts does not make much sense otherwise. – Rui F Ribeiro Dec 31 '18 at 9:44

Generally speaking, the hosts file should be used only to bootstrap a system until it has DNS running. Particularly as you say this is a production system. To that end the only entries that should be in your hosts file are the loopback ones:       localhost
::1             localhost ip6-localhost ip6-loopback
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters

Everything else should be added in DNS.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.