在本地测试网站时,浏览器地址栏显示的地址是localhost,如果你看不惯的话,可以使用域名来替换掉,下面我来说下方法,
我们知道,在不联网的主机上采用hosts文件的方式,即在每台主机上的hosts文件中配置主机名与ip地址对应的关系。那么要实现本地测试网站时使用域名替换localhost,只要手工编辑hosts文件即可。
下面以win8.1为例,教大家如何修改。
首先找到hosts文件,hosts文件的路径是C:\Windows\System32\drivers\etc\hosts。
找到后在hosts文件后加入
127.0.0.1 gitos.net
127.0.0.1 www.gitos.net
保存即可。修改后的hosts文件是这样的:
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a ‘#’ symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 localhost
127.0.0.1 gitos.net
127.0.0.1 www.gitos.net
现在打开浏览器,输入http://gitos.net,回车后即可打开本地的网站了。效果图如下
原创文章,转载请注明: 转载自科技爱好者博客
本文链接地址: 在本地测试网站时使用域名替换localhost (https://www.tujing.site/284)
如果博客对您有帮助,请给我 赞助