一、问题描述
在服务器部署启动了项目,页面显示Invalid Host header。
二、问题分析
新版的webpack-dev-server出于安全考虑,默认检查hostname,如果hostname不是配置内的就不能访问。
三、解决方案
1、跳过host检查
在webpack.conf.js文件,devServer字段下添加disableHostCheck: true
{ devServer: { historyApiFallback: true, hot: true, inline: true, open: true, overlay: true, port: 8180, disableHostCheck: true } }
或者在package.json文件修改scripts命令
webpack-dev-server --disableHostCheck=true
2、直接host设置成你的地址
在webpack.conf.js文件,devServer字段下修改host,这个默认是localhost,可修改成xxx.com。
{ devServer: { host: 'xxx.com' } }
或者在package.json文件修改scripts命令
webpack-dev-server --host=xxx.com或者--public=xxx.com