2
votes

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;


}
1
Is port 80 open on the security group? Is this a single instance or behind a load balance? On a public subnet?strongjz
@strongjz look at the error message from the log, again. The connection to the instance and the security group are fine.Michael - sqlbot
@strongjz Yes 80 is open in security group. nginx is upstreaming the request to 127.0.0.1:5000/swagger-ui.html but still it is giving 502 errorArchit Sud
Can you post your nginx config and the .ebextensions for your beanstalk app.strongjz
@strongjz I have updated my question with nginx configArchit Sud

1 Answers

1
votes

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