mac中hosts文件如何生效?

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1    localhost
255.255.255.255    broadcasthost
::1    localhost
0.0.0.0    account.jetbrains.com
0.0.0.0    www.jetbrains.com
127.0.0.1:3000    www.ylcx2.shop

浏览器输入地址: www.ylcx2.shop
显示没有找到网页

怎么办?

阅读 1.6k
1 个回答

hosts 是 DNS 解析,跟端口有啥关系?

你应该 hosts 里写:

127.0.0.1    www.ylcx2.shop

然后浏览器里访问:

www.ylcx2.shop:3000

P.S. 端口号能不能省略看的是用的什么协议,HTTP 协议默认就是 80 端口、HTTPS 协议默认就是 443 端口,这是 RFC 里规定好的,你可以省略。如果你是 HTTP 协议但不是 80、是 HTTPS 协议但不是 443,那么不能省略。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题