📄hosts文件
C:\Windows\System32\drivers\etc\hosts
hosts文件的作用是保存了域名与ip的映射关系,可以视为对DNS Server的重写,一旦在hosts文件中找到映射关系就不会再向DNS Server发送请求。
🦉DNS解析步骤
1、检查浏览器自身缓存。
2、检查本地操作系统的缓存(hosts)
3、向 DNS Server 发送查询请求
👌配置伪域名
第一步 修改本机hosts配置
# hosts
192.168.1.1 www.baidu.com
复制代码第二步 配置服务器nginx
方式一: root
#nginx.conf
server {
listen 80;
server_name www.baidu.com;
index index.html;
root /xxx/xxx/xxx;
}
复制代码方式二: 转发代理
# nginx.conf
server {
listen 80;
server_name www.baidu.com;
location /{
proxy_pass xxx.xxx.xxx.xxx;
}
}