一个域名,对应一个IP地址
通过DNS域名解析服务器,可以将域名解析为IP地址
这里
通过修改host文件,指定域名的IP地址
host劫持
是指在host文件中,配置域名和IP地址,当访问域名的时候
因为,host文件中已经有了域名所对应的IP地址
所以,不再需要访问DNS服务器进行解析,直接访问对应的IP地址
host文件的位置
C:\Windows\System32\drivers\etc
第一步
编辑host
可以直接使用文本编辑工具
这里,使用SwitchHosts
配置代码
192.168.219.128 test.taotao.com
访问域名
第二步
设置多个域名
配置代码
192.168.219.128 test.taotao.com
192.168.219.128 test2.taotao.com
192.168.219.128 test3.taotao.com
修改nginx.conf配置文件
这里,使用EditPlus修改
添加代码
server{
listen 80;
server_name test.taotao.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html-test;
index index.html index.htm;
}
}
添加home目录
cp -r html html-test
修改欢迎页面
重新加载
访问域名
第三步
配置多个虚拟主机
在nginx.conf文件中,添加代码
server{
listen 80;
server_name test2.taotao.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html-test2;
index index.html index.htm;
}
}
server{
listen 80;
server_name test3.taotao.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html-test3;
index index.html index.htm;
}
}
对应host中的域名配置
创建对应的home文件
修改欢迎页面内容
同理,html-test3
第四步
重新加载
访问test2
访问test3