【问题标题】:"Invalid Host header" Kubernetes cluster on Digital Ocean with React带有 React 的 Digital Ocean 上的“无效主机头”Kubernetes 集群
【发布时间】:2020-12-26 07:53:38
【问题描述】:

在我对我的 react 应用程序进行最新更改之前,我的网站运行良好。当我部署更改时,网页上会出现“Invalid Host header”。

这是我的代码结构:

我可以配置什么来消除这个错误?

这是我的 package.json 文件:

{
  "name": "client",
  "proxy": "http://127.0.0.1:4000",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@material-ui/core": "^4.11.2",
    "@material-ui/icons": "^4.11.2",
    "@material-ui/styles": "^4.11.2",
    "@testing-library/jest-dom": "^5.11.6",
    "@testing-library/react": "^11.2.2",
    "@testing-library/user-event": "^12.6.0",
    "axios": "^0.21.1",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-router-dom": "^5.2.0",
    "react-scripts": "4.0.1",
    "web-vitals": "^0.2.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

这是我的 pod 的日志:

> client@0.1.0 start
> react-scripts start

ℹ 「wds」: Project is running at http://10.244.1.23/
ℹ 「wds」: webpack output is served from
ℹ 「wds」: Content not from webpack is served from /app/public
ℹ 「wds」: 404s will fallback to /
Starting the development server...

Compiled successfully!

You can now view client in the browser.

  Local:            http://localhost:3000
  On Your Network:  http://10.244.1.23:3000

Note that the development build is not optimized.
To create a production build, use npm run build.

谢谢!

【问题讨论】:

  • 提供您所做更改的详细信息,否则 package.json 将没有任何用处。
  • 从浏览器的网络面板检查主机头的值。它应该是您站点的 DNS 名称。检查你的 pod(s) 的日志,找出更多的故障排除指针。
  • @SameerNaik 嗨 Sameer,我上传了我的 pod 的日志。你觉得有什么问题吗?

标签: reactjs kubernetes digital-ocean


【解决方案1】:

所以我通过以下步骤解决了这个问题:

  1. 在我的 react 应用文件夹中运行弹出。

  2. 转到配置文件夹的 webpackDevServer.config.js 文件并更改

    disableHostCheck:!proxy || process.env.DANGEROUSLY_DISABLE_HOST_CHECK === 'true',

到

disableHostCheck: true,

【讨论】:

  • 禁用主机头可能会产生一些安全隐患,正如环境变量 DANGEROUSLY_DISABLE_HOST_CHECK 的名称所暗示的那样。从原始配置来看,如果不使用代理或 env 变量设置为 true,则似乎禁用主机名检查。你能找到它抱怨的主机名的值吗?请也看看这个。 stackoverflow.com/questions/44064460/…
猜你喜欢
  • 2023-04-04
  • 2019-05-22
  • 1970-01-01
  • 2017-07-13
  • 2022-08-05
  • 1970-01-01
  • 2017-05-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多