During web development, you usually need to access websites in the local environment using http: // localhost or 127.0.0.1. However, if there are more websites on the local machine, you have to perform other operations, such as port settings. The results are hard to remember.
I am using a local ubuntu + nginx environment. nginx allows multiple domain names to be set. You only need to point to different storage locations. Then, how should we set a domain name that we have selected, and this domain name only accesses a local website?
In windows, there is a file system32/drivers/etc/host. In this file, you can configure the domain name to point to the local IP address to achieve the above purpose.
In ubuntu (usually in linux), the hosts file is searched under/etc, which is equivalent to the same host file. If not, create a new one.
Sudo vi/etc/hosts
Add the required items in the following format:
<IP> <HOSTNAME>. <DOMAIN> <ALIAS>
The following are some of my configurations:
127.0.0.1 www.v.com # enter the www.v.com domain name in my computer browser to access my local website. Of course, it is limited to local. I thought I had registered the domain www.v.com.
127.0.0.1 www. B2B .com
127.0.0.1 www.itdiffer.org
127.0.0.1 www.weixin.com
Note that in Nginx, you must configure the conf to make these domain names accessible.