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;
}
-
Is port 80 open on the security group? Is this a single instance or behind a load balance? On a public subnet?strongjz– strongjz2017年08月06日 00:34:12 +00:00Commented 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.Michael - sqlbot– Michael - sqlbot2017年08月06日 03:31:12 +00:00Commented 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 errorArchit Sud– Archit Sud2017年08月06日 08:56:43 +00:00Commented Aug 6, 2017 at 8:56
-
Can you post your nginx config and the .ebextensions for your beanstalk app.strongjz– strongjz2017年08月06日 21:43:58 +00:00Commented Aug 6, 2017 at 21:43
-
@strongjz I have updated my question with nginx configArchit Sud– Archit Sud2017年08月08日 03:27:14 +00:00Commented Aug 8, 2017 at 3:27
1 Answer 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).
1 Comment
Explore related questions
See similar questions with these tags.