6
votes

I deployed a Spring Boot app on AWS Elastic Beanstalk. I am facing a 502 Bad Gateway error. I cannot find anything useful from the logs

/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: "...."

I do not have any html files for front-end. I just want to upload deploy the api to share the documentation from swagger ui.

3

3 Answers

12
votes

It's because server is listening to 5000, Adding "server.port=5000" to application.properties fixed the issue.

9
votes

This happens because the application load balancer by default points to the Port 80 of the nginx server in EC2 instance. The nginx is configured to forward requests to Port 5000 by default, whereas out application server runs on Port 8080.

Default Nginx Configuration

Default Nginx Configuration

Expected Nginx Configuration

Expected Nginx Configuration

  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 enter image description here

Refer AWS Document: 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. enter image description here

  2. Another way to fix this would be to set port to 5000 in the spring boot application by using server.port property.

2
votes

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. My Java version was 11, and my platform was only Java 8 for Amazon Linux. So changing it to 8 in my base pom.xml fixed it.