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

1

8

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)

Eos answered 3/5, 2016 at 19:14 Comment(0)
F
10

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.

Frugivorous answered 3/5, 2016 at 20:3 Comment(4)
Thank you for your answer. Finally I opted for a server TomCat.Eos
@ChristianAmani, if you opted for TomCat, why did you accept Ravi's answer?Eddington
I accepted Ravis's reply because he was right. By default, Elastic Beanstalk configures the nginx proxy server to forward requests to the application on port 5000. Now my application was listening on port 4567. So Which caused the mistake I received. To resolve it, I just had to replace the default port by setting the PORT system property to the port my application was listening to.Eos
Thanks man you saved my lot of time.. I my case I am having spring boot app which I was running on local with some other port like 8888 but from Stackdriver logging i saw that upstream was expecting the port 8080. So i changed my application port changed to 8080 from 8888 and deployed back to the app engine service which deployed successfully. thanks for the clue.Auriferous

© 2022 - 2024 — McMap. All rights reserved.