【发布时间】:2020-02-05 09:41:39
【问题描述】:
我正在尝试重命名我在开发中使用的 localhost。
我更新了我的C:\Windows\System32\drivers\etc\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 my-dev-environment.com // <===== ADDED THIS LINE
127.0.0.1:8080 my-dev-environment.com // <===== I ALSO TRIED THIS
但我不断收到此错误:
This site can’t be reached
"my-dev-environment.com" refused to connect
我正在使用webpack-dev-server 进行开发,这是我当前的配置:
webpack.config.js
devServer: {
contentBase: './public',
compress: true,
hot: true,
historyApiFallback: {
index: '/app.html'
},
index: 'app.html'
},
问题
我做错了吗?为什么它不起作用?
更新(已解决):
根据以下答案中的@Joel 建议,我已将此添加到我的webpack.config.js
devServer: {
public: 'my-dev-environment.com',
port: 80,
}
这是在我的hosts 文件中:
127.0.0.1 my-dev-environment.com
现在我可以通过 my-dev-environment.com 访问它
【问题讨论】:
-
重启所有打开的浏览器,刷新 dns 缓存。那么你应该好好去。另外,试试
127.0.0.1 localhost my-dev-environment.com -
谢谢!如何
flush dns cache? -
windows + r =>
ipconfig /flushdns -
那么,如果上述方法不起作用。重启你的机器:)
-
@Joel Hey Joel,什么都试过了。包括重新启动我的电脑,但没有任何效果!这可能与某些
webpack-dev-server配置有关吗?
标签: webpack dns localhost webpack-dev-server hosts