question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

503 connect() failed (111: Connection refused) while connecting to upstream

See original GitHub issue

Questions

I set up flask + jwilder with basic auth and got success code… Then i set up gunicorn + jwilder, but got error,

My error :

[error] 52#52: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.20.0.1, server: my.local, request: "GET / HTTP/1.1", upstream: "http://172.20.0.2:8000/", host: "my.local"

My working code :

  • Docker-compose.py
version: '3.7'
services:

  web:
    build: ./myapp
    restart: always
    networks:
      - proxynet
    environment:
      - VIRTUAL_HOST=my.local
      - VIRTUAL_PORT=5000
    expose:
      - 5000

  nginx-proxy:
    container_name: nginx-proxy
    restart: always
    image: jwilder/nginx-proxy:alpine
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx-proxy/secrets/htpasswd:/etc/nginx/htpasswd
      - ./nginx-proxy/conf.d:/etc/nginx/conf.d
      - ./nginx-proxy/vhost.d:/etc/nginx/vhost.d
      - ./nginx-proxy/html:/usr/share/nginx/html
      - ./nginx-proxy/certs:/etc/nginx/certs
      - /var/run/docker.sock:/tmp/docker.sock:ro
    networks: 
      - proxynet

networks:
  proxynet:
    external: true
  • Dockerfile.py
FROM python:3.4-alpine
ADD . /code
WORKDIR /code
RUN pip install -r requirements
CMD ["python", "app.py"]

My app.py

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello world!'

if __name__ == '__main__':
    app.run(host='0.0.0.0')

Ok this upper code is run, and somehow works… but my question is, when i’am using gunicorn, i got 503/502…

My error code :

Docker-compose.py

version: '3.7'
services:

  app:
    build: 
      context: .
      dockerfile: ./app/Dockerfile
    environment: 
      - VIRTUAL_HOST=my.local
      - VIRTUAL_PORT=8000
    expose:
      - 8000
    networks: 
      - proxynet

  nginx-proxy:
    container_name: nginx-proxy
    restart: always
    image: jwilder/nginx-proxy:alpine
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx-proxy/secrets/htpasswd:/etc/nginx/htpasswd
      - ./nginx-proxy/conf.d:/etc/nginx/conf.d
      - ./nginx-proxy/vhost.d:/etc/nginx/vhost.d
      - ./nginx-proxy/html:/usr/share/nginx/html
      - ./nginx-proxy/certs:/etc/nginx/certs
      - /var/run/docker.sock:/tmp/docker.sock:ro
    networks: 
      - proxynet

networks:
  proxynet:
    external: true

Dockerfile.py

FROM python:latest
ADD ./app /root
WORKDIR /root
RUN pip install -r requirements.txt
CMD ["/usr/local/bin/gunicorn", "manage"]

requirements.txt

Flask==1.0.2
gunicorn==19.9.0

manage.py

import os
from flask import Flask 
application = Flask(__name__)

@application.route("/")
def hello():
    return "<h1 style='color:blue'>Hello There!</h1>"

if __name__ == "__main__":
    application.run(host='0.0.0.0')

This last code result error :

[error] 52#52: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.20.0.1, server:blabla.. 

Thanks for help… Budi

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
wilcoolcommented, Aug 13, 2019

Is solved?

0reactions
algertgjokacommented, Jan 17, 2020

Had the same problem with docker 19 on CentOS 8, once I downgraded to 18 everything seems to magically work again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

connect() failed (111: Connection refused) while connecting to ...
Hi all,. Followed this tutorial to get Let's Encrypt working on my Nest.js/Node server. Everything works - running sudo nginx -t returns:.
Read more >
docker - NGINX (111: Connection refused) error while ...
connection refused means nothing is listening on the target ip/port. Make sure your application on the backend is running and is listening on ......
Read more >
Gunicorn + jwilder ~ 503 connect() failed (111 - Stack Overflow
My working code is flask + jwilder(nginx) with basic auth, buth when i'm using gunicorn + jwilder(nginx) i'm got error.
Read more >
(111: Connection refused) while connecting to upstream
Symptoms. The following errors can be found at Domains > example.com > Logs: [error] 15231#0: *12218 connect() failed (111: Connection ...
Read more >
1944 (connect() failed (111: Connection refused) while ... - nginx
The error message suggests that there is a problem with your upstream server, likely it is not running or overloaded. The message in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found