Skip to content

Local domain configuration via hosts file

Local domain configuration via the hosts file is a method of mapping hostnames to IP addresses on a specific machine, overriding the responses from a Domain Name System (DNS) server^[600-developer__tools__security__CA.md]. This is often used during local development to simulate a specific domain environment or to test configurations (such as HTTPS with a Self-Signed Certificate) before deploying to a live server^[600-developer__tools__security__CA.md].

Configuration

On Unix-like systems (such as Linux), the hosts file is typically located at /etc/hosts^[600-developer__tools__security__CA.md].

To configure a local domain, an entry must be added to this file that maps the local loopback IP address (127.0.0.1) to the desired domain name^[600-developer__tools__security__CA.md].

Syntax

The basic syntax for the entry is IP_address hostname^[600-developer__tools__security__CA.md].

Example

The following example demonstrates how to map a custom domain (e.g., test.example.com) to the local machine^[600-developer__tools__security__CA.md]:

127.0.0.1 <你的域名>
127.0.0.1 localhost
127.0.1.1 ubuntu
(Note: <你的域名> should be replaced with the actual domain you wish to configure, such as yudady.tk)^[600-developer__tools__security__CA.md].

  • SSL/TLS
  • [[Reverse Proxy]]
  • [[Local Development Environment]]

Sources

^[600-developer__tools__security__CA.md]