2

I have hosted my spring boot application on AWS elastic-beanstalk, but when I try to access it with the public URL, it is gives me 502 Gateway Error. In the log, I can see the below error: 2017/08/05 20:10:33 [error] 22965#0: *157 connect() failed (111: Connection refused) while connecting to upstream, client: XXX.68.241.XXX, server: , request: "GET /swagger-ui.html HTTP/1.1", upstream: "http://127.0.0.1:5000/swagger-ui.html", host: "XXXXXXXX-env.XXX.us-west-2.elasticbeanstalk.com"

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

events {
  worker_connections 1024;
}

http {
  log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
  '$status $body_bytes_sent "$http_referer" '
  '"$http_user_agent" "$http_x_forwarded_for"';


  upstream tomcat_servers{
    ip_hash;
    server 127.0.0.1:5000;
    keepalive 256;
  }

  access_log  /var/log/nginx/access.log  main;

  sendfile            on;
  tcp_nopush          on;
  tcp_nodelay         on;
  keepalive_timeout   65;
  types_hash_max_size 2048;

  include             /etc/nginx/mime.types;
  default_type        application/octet-stream;


}
Archit Sud
  • 129
  • 8
  • Is port 80 open on the security group? Is this a single instance or behind a load balance? On a public subnet? – strongjz Aug 06 '17 at 00:34
  • 1
    @strongjz look at the error message from the log, again. The connection to the instance and the security group are fine. – Michael - sqlbot Aug 06 '17 at 03:31
  • @strongjz Yes 80 is open in security group. nginx is upstreaming the request to http://127.0.0.1:5000/swagger-ui.html but still it is giving 502 error – Archit Sud Aug 06 '17 at 08:56
  • Can you post your nginx config and the .ebextensions for your beanstalk app. – strongjz Aug 06 '17 at 21:43
  • @strongjz I have updated my question with nginx config – Archit Sud Aug 08 '17 at 03:27
  • Can you access your spring-boot application directly, without going over nginx? i.e. http://XXXXXXXX-env.XXX.us-west-2.elasticbeanstalk.com:5000/swagger-ui.html ? Also, is your spring-boot application configured to listen to port 5000, to which nginx forwards the requests? Configuration would be server.port=5000 – Andrei Socaciu Aug 08 '17 at 09:18
  • @AndreiSocaciu It keeps loading no error no success if I add :5000 – Archit Sud Aug 08 '17 at 09:58
  • Did you open port 5000 on the security group for the test above? – Andrei Socaciu Aug 08 '17 at 11:16

1 Answers1

1

I would double check the port your Spring boot application is running on.

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. For this post, we will change the port the Spring Boot application listens on.

The easiest way to do this is to specify the SERVER_PORT environment variable in the Elastic Beanstalk environment and set the value to 5000. (The configuration property name is server.port, but Spring Boot allows you to specify a more environment variable-friendly name).

https://aws.amazon.com/blogs/devops/deploying-a-spring-boot-application-on-aws-using-aws-elastic-beanstalk/

Answered here as well

Help on how to update the port

Community
  • 1
  • 1
strongjz
  • 4,271
  • 1
  • 17
  • 27