1、利用本地机器解析host域名
配置本机的host文件,路径在:C:\Windows\System32\drivers\etc\host
这里会提示没有权限,可以先右键这个文件点属性,修改用户的权限。
编辑这个文件,在最下方加入以下命令:
127.0.0.1 localhost user.gmall.com cart.gmall.com manage.gmall.com www.gmall.com
把本地的ip地址127.0.0.1和localhost解析成user.gmall.com、cart.gmall.com、 manage.gmall.com、www.gmall.com。
2、打开系统的cmd命令,输入ipconfig /flushdns刷新DNS的解析缓存
这样访问:http://user.gmall.com:8080/index相当于http://localhost:8080/index
这样访问:http://cart.gmall.com:8080/index相当于http://localhost:8080/index
这样访问:http://manage.gmall.com:8080/index相当于http://localhost:8080/index
这样访问:http://www.gmall.com:8080/index相当于http://localhost:8080/index
3、但是看到后边还有一个端口,看着有点不太顺眼!可以通过软件Nginx去端口号。
链接: https://pan.baidu.com/s/1uPQRVyyOupX0eSiMuCYEvg 提取码: a6y1
在conf的Nginx.conf添加以下代码:
upstream user.gmall.com{
server 127.0.0.1:8080;
}
server{
listen 80;
server_name user.gmall.com;
location / {
proxy_pass http://user.gmall.com;
proxy_set_header X-forwarded-for $proxy_add_x_forwarded_for;
}
}
之后运行Nginx.exe,就可以直接访问http://user.gmall.com/index,实现了去端口8080!非常的完美!!!
4、设置开机自启,把nginx.exe文件复制到这个路径下:
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp