connect() failed (111: Connection refused) while connecting to upstream. Java (SparkJava) amazon Elastic

Christian Amani picture Christian Amani · May 3, 2016 · Viewed 7.5k times · Source

Trying to deploy my first app (Back-end). But I meet an error of the type 502 Bad Gateway.

2016/05/03 14:46:14 [error] 2247#0: *19 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.43.183, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "myHost.eu-west-1.elasticbeanstalk.com"
2016/05/03 14:50:23 [error] 2566#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.8.36, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "myHost.eu-west-1.elasticbeanstalk.com"
2016/05/03 14:55:04 [error] 2566#0: *61 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.43.183, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "myHost.eu-west-1.elasticbeanstalk.com"

I use for my Back-End Framework SparkJava, which launches on the port 4567. Thus I Extended the configuration of Nginx (nginx/1.8.1). But the problem always persists.

server {
    listen 4567 default_server;
    listen [::]:4567 default_server ipv6only=on;
}

For Information : My Back-End communicates with a database (RDS aws amazon)

Answer

RaviTezu picture RaviTezu · May 3, 2016

From your logs: upstream: "http://127.0.0.1:5000/" I see, nginx is trying to connect to 5000 port on the same machine and it is refusing the connections. What is running on 5000 port? You may need to look into that.