3

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;
}
asked Aug 5, 2017 at 20:18
8
  • Is port 80 open on the security group? Is this a single instance or behind a load balance? On a public subnet? Commented Aug 6, 2017 at 0:34
  • 1
    @strongjz look at the error message from the log, again. The connection to the instance and the security group are fine. Commented Aug 6, 2017 at 3:31
  • @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 error Commented Aug 6, 2017 at 8:56
  • Can you post your nginx config and the .ebextensions for your beanstalk app. Commented Aug 6, 2017 at 21:43
  • @strongjz I have updated my question with nginx config Commented Aug 8, 2017 at 3:27

1 Answer 1

3

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

answered Aug 8, 2017 at 12:30
Sign up to request clarification or add additional context in comments.

1 Comment

I was not adding port number in the EBS environment configuration

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.