Configure the host file to set the local domain name.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.