15

I got this message

connect() failed (111: Connection refused

Here is my log:

-------------------------------------
/var/log/nginx/error.log
-------------------------------------
2018/10/21 06:16:33 [error] 4282#0: *2 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.4.119, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8081/", host: "hackingdeal-env.qnyexn72ga.ap-northeast-2.elasticbeanstalk.com"
2018/10/21 06:16:33 [error] 4282#0: *2 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.4.119, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:8081/favicon.ico", host: "hackingdeal-env.qnyexn72ga.ap-northeast-2.elasticbeanstalk.com", referrer: "http://hackingdeal-env.qnyexn72ga.ap-northeast-2.elasticbeanstalk.com/"

I am using nodejs/express Elastic Beanstalk env.

I have one nginx related file in

.ebextensions/nginx/conf.d/proxy.conf

Upper file contains:

client_max_body_size 50M;

Whenever I try to get my webpage I got 502 bad gateway.

What's wrong with my app?

leonkong
  • 459
  • 3
  • 5
  • 15

3 Answers3

7

Just recording my incident here just in case it helps someone or my future self. I had a Django application that had SECURE_SSL_REDIRECT set to True. Since I had no load balancers configured to handle HTTPS traffic I was getting a timeout. Setting it to False fixed the issue. Couple of days wasted on that one.

MadeOfAir
  • 2,933
  • 5
  • 31
  • 39
6

111 connection refused likely means your app isn't running on the server/port combination. Also check that the security group for your app instance (or load balancer) has an inbound rule set to allow traffic from the nginx instance

sofcal
  • 490
  • 3
  • 7
  • 4
    how can I allow traffic from the nginx instance?? – leonkong Oct 22 '18 at 01:05
  • 1
    You should have a security group for your nginx instance and your beanstalk load balancer. On the load balancer sg, add an inbound rule and select the security group of the nginx instance – sofcal Oct 22 '18 at 08:04
1

I was dealing with this error on my NodeJS application (NEXTJS). Posting this here just in case is useful for someone.

My error was thet the deploy command failed at the build step (next build), which means the Node server never restarted. For that reason nginx could not find the server. You can find this kind of errors in the web.stdout.log

I tested my build command locally, fixed the errors and it worked!

luiyit
  • 46
  • 6