I'm trying to create alias for my local website which is runned by vagrant(virtual box), hence I want redirect any requests from site.ru to 192.168.10.10/site.ru via /etc/hosts
file. In the hosts file I have the following:
...
192.168.10.10/site.ru site.ru
However it doesn't work as I want. When I go to site.ru I'm appear in the 'real' site. I hope anybody understand me to answer for my question..
What did I do wrong?
UPDATE: Solution: How to setup mass dynamic virtual hosts in nginx?
You can definitely direct a host name to an IP address on your LAN with Ubuntu's
hosts
file, but it does not support the particular syntax you're using. Fromman hosts
:The hosts file in Ubuntu does not direct hostnames with other hostnames, but only with IP addresses.
Therefore, instead of writing:
You should instead write:
This will cause
site.ru
to be resolved to192.168.10.10
instead of whatever it would otherwise be resolved to via DNS.However, this may or may not effectively direct all traffic that is (conceptually) associated with the
site.ru
domain name. In particular, it will typically not be sufficient to cause a domain likewww.site.ru
to be mapped to 192.168.10.10 as well. To achieve that, addwww.site.ru
explicitly:(You can alternatively make a separate line for it, if you prefer. This line must also start with an IP address.)
But
hosts
will not direct traffic to a specific folder on a website.If by
192.168.10.10/site.ru
you mean thesite.ru
directory on the web server at192.168.10.10
(that is, if you are using/
as a path separator), you cannot use thehosts
file to do this.hosts
files do not facilitate that behavior on any operating system; it is fundamentally unrelated to whathosts
files do.The reason this cannot work is that hosts files redirect host names to IP addresses. But
192.168.10.10/site.ru
is not an IP address. It's an IP address followed by directory retrieval information sent to the IP address through an application-layer protocol. See this article on the meaning of different parts of a URL (and how only one part is resolved via IP).The proper solution in this sort of situation is to configure the web server to serve different content depending on which host name is used to access the site. This can work because the HTTP protocol includes the ability of web browsers to tell the web server what host name it is using (and essentially all web browsers send this information whenever it's applicable).
If you have the ability to make changes to the web server and need help setting up "virtual hosts," and the web server is an Ubuntu system, please feel free to post a separate question about that here.
If you don't have the ability to make changes to the web server, you should talk to whoever does.
If even that is absolutely not an option, then you should edit your question (or post a new one, your choice) to clarify your situation in detail. A messier workaround that fits your needs might be possible. It would probably involve an HTTP proxy server running on each client machine and redirecting HTTP traffic by URL.
That is the right syntax
IP ADDRESS SITE.COM
real example127.0.0.134 hackme.org