Hi I am new AWS and trying to deploy spring boot application in Elastic Beanstalk . Deployment is successful but not able to access application .Getting 502 Bad Request Gateway nginx/1.10.1 error. Deployment is done on Configuration 64bit Amazon Linux 2016.09 v2.2.0 running Java 8 (nginx proxy server). Is thier any way to solve this issue. After doing googling i found it is because of port mismatch.I wanted to know where i should change the port numbers.
-
Possible duplicate of [Java AWS Server: 502 Bad Gateway nginx/1.8.1](https://stackoverflow.com/questions/36491744/java-aws-server-502-bad-gateway-nginx-1-8-1) – Alex R Oct 10 '18 at 20:26
-
Just to validate if it is a nginx error, could you try to consume your spring boot using curl behind balancer? I mean at inside your ec2 instance... curl http://localhost:port/rest_controller_endpoint – JRichardsz Nov 23 '19 at 16:56
3 Answers
From AWS documentation:
By default, Spring Boot applications will listen on port 8080. Elastic Beanstalk assumes that the application will listen on port 5000. There are two ways to fix this discrepancy: change the port Elastic Beanstalk is configured to use, or change the port the Spring Boot application listens on.
You can set the port in server.port
property in application.properties
or set it through environment as described in the document referred above by setting SERVER_PORT environment property.

- 8,007
- 3
- 37
- 56
I also had the same issue. And the reason was the fact that i didn't correctly generate my jar. Instead of taking the classic jar from an clean install take the one from a clean package spring-boot:repackage

- 11
- 1
For me setting PORT
(instead of SERVER_PORT
) as environment variable with value 8080
worked for me.

- 8,221
- 1
- 59
- 63