vue nginx Invalid Host header问题解决

1,083 阅读1分钟

nginx配置好启动后,访问配置的地址时,出现Invalid Host header问题,网上搜索了很多,基本都是在vue.config.js或者webpack.dev.conf.js的devServer中添加disableHostCheck:true;但是设置了会出现问题:

ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
 - options has an unknown property 'disableHostCheck'. These properties are valid:
   object { allowedHosts?, bonjour?, client?, compress?, devMiddleware?, headers?, historyApiFallback?, host?, hot?, http2?, https?, ipc?, liveReload?, magicHtml?, onAfterSetupMiddleware?, onBeforeSetupMiddleware?, onListening?, open?, port?, proxy?, server?, setupExitSignals?, setupMiddlewares?, static?, watchFiles?, webSocketServer? }
    at validate (D:\Yll\second-kill-front\node_modules\webpack-dev-server\node_modules\schema-utils\dist\validate.js:115:11)    at new Server (D:\Yll\second-kill-front\node_modules\webpack-dev-server\lib\Server.js:231:5)
    at serve (D:\Yll\second-kill-front\node_modules\@vue\cli-service\lib\commands\serve.js:185:20)
    at processTicksAndRejections (internal/process/task_queues.js:85:5)error Command failed with exit code 1.info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

解决办法:将

devServer:{
    ...
    disableHostCheck:true,
    ...
}

变为:

devServer:{
    ...
    historyApiFallback: true,
    allowedHosts: "all",
    ...
}