简体   繁体   English

502 错误网关 Elastic Beanstalk Spring Boot

[英]502 bad gateway Elastic Beanstalk Spring Boot

I deployed a Spring Boot app on AWS Elastic Beanstalk.我在 AWS Elastic Beanstalk 上部署了一个 Spring Boot 应用程序。 I am facing a 502 Bad Gateway error.我正面临 502 Bad Gateway 错误。 I cannot find anything useful from the logs我从日志中找不到任何有用的东西

/var/log/nginx/error.log /var/log/nginx/error.log

2019/02/10 02:12:54 [error] 3257#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: ...., server: , request: "GET / HTTP/1.1", upstream: " http://127.0.0.1:5000/ ", host: "...." 2019/02/10 02:12:54 [错误] 3257#0:*1 connect() 失败(111:连接被拒绝),同时连接到上游,客户端:....,服务器:,请求:“GET / HTTP /1.1", 上游: " http://127.0.0.1:5000/ ", 主机: "...."

I do not have any html files for front-end.我没有任何用于前端的 html 文件。 I just want to upload deploy the api to share the documentation from swagger ui.我只想上传部署 api 以共享来自 swagger ui 的文档。

这是因为服务器正在侦听 5000,将“server.port=5000”添加到 application.properties 解决了该问题。

This happens because the application load balancer by default points to the Port 80 of the nginx server in EC2 instance.发生这种情况是因为应用程序负载均衡器默认指向 EC2 实例中 nginx 服务器的端口 80 The nginx is configured to forward requests to Port 5000 by default, whereas out application server runs on Port 8080 .默认情况下,nginx 配置为将请求转发到端口 5000 ,而 out 应用程序服务器运行在端口 8080 上

Default Nginx Configuration默认 Nginx 配置

默认 Nginx 配置

Expected Nginx Configuration预期的 Nginx 配置

预期的 Nginx 配置

  1. This can be fixed using an environment property named PORT and pointing it to 8080 Go to configuration > Environment Properties and add the property这可以使用名为PORT的环境属性并将其指向 8080 来修复。转到配置 > 环境属性并添加属性在此处输入图片说明

Refer AWS Document: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/java-se-nginx.html请参阅 AWS 文档: https : //docs.aws.amazon.com/elasticbeanstalk/latest/dg/java-se-nginx.html

  1. Another option to fix this is to point application load balancer to the application server port(8080) directly instead of the nginx(80. You can configure 8080 as the process port.解决此问题的另一种选择是将应用程序负载均衡器直接指向应用程序服务器端口(8080),而不是 nginx(80)。您可以将 8080 配置为进程端口。 在此处输入图片说明

  2. Another way to fix this would be to set port to 5000 in the spring boot application by using server.port property.解决此问题的另一种方法是使用 server.port 属性在 Spring Boot 应用程序中将端口设置为 5000。

My issue was my Java version didn't match the platform I'm running with Elastic Beanstalk, even tho my server.port was on 5000 .我的问题是我的Java版本与我使用 Elastic Beanstalk 运行的平台不匹配,即使我的server.port是在5000 My Java version was 11, and my platform was only Java 8 for Amazon Linux.我的 Java 版本是 11,我的平台只有适用于 Amazon Linux 的 Java 8。 So changing it to 8 in my base pom.xml fixed it.所以在我的基础pom.xml中将它更改为 8 修复了它。

在 Elastic BeanStalk 中更新环境属性上的端口号为我解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将Spring Boot应用程序部署到Elastic Beanstalk时出现502 Bad Gateway - 502 Bad Gateway when deploying Spring Boot application to Elastic Beanstalk Beanstalk 502 Bad Gateway Spring应用程序 - Beanstalk 502 Bad Gateway Spring application spring 引导 + gcloud +“502 错误网关” - spring boot + gcloud + "502 Bad Gateway" 在AWS Elastic Beanstalk上部署Spring Boot应用程序 - 获得502错误 - Deploying Spring Boot app on AWS Elastic Beanstalk — getting 502 error 当我将 SpringBoot 应用程序部署到 AWS Elastic Beanstalk 并且无法从本地 SpringBoot 连接到 RDS 时出现 502 bad gateway - 502 bad gateway when I deploy SpringBoot application to AWS Elastic Beanstalk and cannot connect to RDS from local SpringBoot 调用在GCP中部署的Spring Boot应用程序中配置的端点时获取502 Bad Gateway - Getting 502 Bad Gateway while calling an end point configured in spring boot application deployed in GCP 使用Elastic BeansTalk CLI部署Spring Boot应用程序 - Deploy Spring Boot application with Elastic BeansTalk CLI 在Elastic Beanstalk上使用Opencv运行Spring Boot - Running Spring boot with Opencv on Elastic Beanstalk 弹性beantalk + Spring Boot + Array属性 - Elastic beanstalk + Spring Boot + Array properties Spring Boot 应用程序无法在 Elastic Beanstalk 上启动 - Spring Boot App Fails to Start on Elastic Beanstalk
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM