Search code examples
amazon-web-servicesspring-bootamazon-elastic-beanstalk

Why I need set SERVER_PORT:5000 in AWS Beanstalk to make Spring Boot app to work?


I have simple CRUD spring boot app that I want to deploy to AWS via Beanstalk.

If I follow default steps and only choose custom VPC - app doesnt work.

If I doing the same and set SERVER_PORT: 5000 in env variables - app is working and I can use my API.

I have 2 questions:

  1. Why I need set SERVER_PORT to 5000?
  2. Why it is working now on port 80 and not 8080 as it is default port that it is running locally?

I solved the issue by adding env variable, but I want to know why I have to do it.


Solution

  • By default Spring Boot listens on port 8080. However, by default the Elastic Beanstalk environment runs a reverse proxy server on port 80 and forwards traffic to your application on port 5000. Thus, to have the traffic proxied correctly to your application, you either have to modify the reverse proxy to forward to port 8080, or just set the SERVER_PORT environment variable (that Spring Boot automatically detects, and uses to configure what port it listens on) to port 5000.

    More details are documented here.