React:AWS Elastic Beanstalk 上的 502 Bad Gateway

React: 502 Bad Gateway on AWS Elastic Beanstalk

我正在尝试使用 AWS Elastic Beanstalk 部署 Web 应用程序前端。由于 NodeJS 使用 3000 我将 beantalk env 的 PORT 环境变量更改为 3000.

问题: 部署在 AWS 控制台中显示成功,但当我尝试访问该网页时,我收到 502 错误网关。我筛选了日志,节点似乎是 stuck/looping 在 Starting the development server... 阶段。

web.stdout.log 文件反复打印以下内容:

Jul  5 20:34:41 ip- web: > webapp@0.1.0 start /var/app/current
Jul  5 20:34:41 ip- web: > react-scripts start
Jul  5 20:34:45 ip- web: #033[34mℹ#033[39m #033[90m「wds」#033[39m: Project is running at http://xx.xx.xx/
Jul  5 20:34:45 ip- web: #033[34mℹ#033[39m #033[90m「wds」#033[39m: webpack output is served from
Jul  5 20:34:45 ip- web: #033[34mℹ#033[39m #033[90m「wds」#033[39m: Content not from webpack is served from /var/app/current/public
Jul  5 20:34:45 ip- web: #033[34mℹ#033[39m #033[90m「wds」#033[39m: 404s will fallback to /
Jul  5 20:34:45 ip- web: Starting the development server...

到目前为止我尝试过的:

  1. 我看到一个建议,该实例可能 运行 内存不足,所以我将实例切换到 t3.small,但它没有用。还是卡住了

  2. 我没有更改 PORT 环境变量,而是在 package.json 中将 Node 的默认端口更改为 8080(beanstalk 中的 nginx 默认端口)。它仍然卡住了。 我的猜测是负载平衡器需要配置为监听端口 3000。但我不知道如何正确地做到这一点。

有人可以帮我解决这个问题吗?如果需要任何额外信息,我会提供。

使用 npm run build 提供静态内容解决了我的问题。

我认为 运行 EB 上的开发服务器是不可能的。