本地机器配置域名以及去端口

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值