0

Hello i want to have three virtual severs in my localhost Virtual machine Ubbuntu 18.04.

Id like one localhost -> /var/www/html one onlyoffice.eduardo.com -> /var/www/onlyoffice ( document server) another one to nextcloud.eduardo.com -> /usr/share/nginx/nextcloud16

1 - Which etc/hosts would be better:

127.0.0.1 localhost
127.0.0.1 onlyoffice.eduardo.com
127.0.0.1 nextcloud.eduardo.com

or all in the same line

127.0.0.1 localhost onlyoffice.eduardo.com nextcloud.eduardo.com

I suppose that it would look for the name in order when i put http://onlyoffice.eduardo.com for example....

2 - Would it better to have different ips:

127.0.0.1 localhost
127.0.0.2 onlyoffice.eduardo.com
127.0.0.3 nextcloud.eduardo.com

Any other files should i touch ?

The general idea is to have the nextcloud, document server ( onlyoffice) in same place. Id alsolike to connect nextcloud onlyoffice app to http://onlyoffice.eduardo.com

So id have to conf somehow in sites-avalaible and sites-enabled.. Id prefer to use nginx instead of apache.

Thanks

My work so far: https://drive.google.com/open?id=1I2ZiRUKqmm8u5U5TsqyoOKUvfTwY-SPA Thanks in advance

1
  • Please include in your question what have you tried so far. Most probably you need to include your appache/nginx configuration. Also you have to be aware that virtual hosts with names configured in /etc/hosts will work only from hosts where you configure hosts file in that way
    – mrc02_kr
    Nov 13, 2019 at 11:59

1 Answer 1

2

The reason to configure the various hostnames to /etc/hosts is to allow the local web browser (client) to know which IP address to connect to reach the respective hostname, nothing else.

If you configure the web server to bind each virtual host to a different 127.0.0.* IP address, then you must also use associate the hostnames with the respective IP addresses. Otherwise the client won't be able to connect to the right virtual host. This would be IP-based virtual hosting.

But the webserver won't need /etc/hosts at all, since it will be able to look at the headers of the HTTP request and see which hostname was actually used in the request. Even using just one port and one IP address, it will be able to present different content according to the hostname used in the request, if configured to do so. This is known as name-based virtual hosting.

Both Apache and nginx will be able to handle either method; it's just a matter of deciding which one to use. The name-based method will require less IP addresses, which makes it the most widely-used one in public webservers, since static IP addresses are a limited resource.


In /etc/hosts, the "all names in the same line" makes it unambiguous that the first listed name is the primary one and the rest are aliases - sort of similar to using the CNAME records in DNS. If a client does both a forward and a reverse lookup, e.g. for HTTPS certificate verification purposes, this format is the most likely to pass the reverse lookup check without causing security warnings.

If you use "multiple lines with the same IP address" in /etc/hosts, and perform a reverse lookup, only the first line with the matching IP will be returned.

In Linux, the nslookup command will often explicitly query DNS only. To test the complete hostname resolution process just like an application would do, you should use getent hosts <hostname-or-IP-address>. With this command, you can verify the effect of different /etc/hosts configurations for yourself.


In StackExchange, the standard process would be one question per question post. Based on the title and the majority of contents of your post, this question was about /etc/hosts. If you need help on configuring your webserver, you should post another question for that, rather than attempt to stretch this one into an extended discussion.

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.