1

I configured my django-uwsgi-nginx using docker compose with the following files.

From browser "http://127.0.0.1:8000/" works fine and gives me the django default page

From browser "http://127.0.0.1:80" throws a 502 Bad Gateway


dravoka-docker.conf

upstream web {
    server 0.0.0.0:8000;
}

server {
    listen 80;
    server_name web;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        alias "/dravoka-static/";
    }

    location / {
        include         uwsgi_params;
        proxy_pass      http://web;
    }
}

nginx/Dockerfile

FROM nginx:latest
RUN echo "---------------------- I AM NGINX --------------------------"
RUN rm /etc/nginx/conf.d/default.conf
ADD sites-enabled/ /etc/nginx/conf.d
RUN nginx -t

web is just from "django-admin startproject web"

docker-compose.yaml

version: '3'

services:

  nginx:
    restart: always
    build: ./nginx/
    depends_on:
      - web
    ports:
      - "80:80"

  web:
    build: .
    image: dravoka-image
    ports:
      - "8000:8000"
    volumes:
      - .:/dravoka
    command: uwsgi /dravoka/web/dravoka.ini

Dockerfile

# Ubuntu base image
FROM ubuntu:latest
# Some installs........
EXPOSE 80
Pratik Shah
  • 1,782
  • 1
  • 15
  • 33
Srinath Ganesh
  • 2,496
  • 2
  • 30
  • 60
  • terminal> nginx_1 | 2018/06/18 11:18:29 [error] 7#7: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.23.0.1, server: web, request: "GET / HTTP/1.1", upstream: "http://0.0.0.0:8000/", host: "127.0.0.1" – Srinath Ganesh Jun 18 '18 at 11:23

1 Answers1

1

When you say from the docker instance , you are running curl from with in the container ?? or you are running the curl command from your local ?

if you are running it from your local , update your docker-compose's web service to following

...
  web:
    build: .
    image: dravoka-image
    expose:
      - "8000:8000"
    volumes:
      - .:/dravoka
    command: uwsgi /dravoka/web/dravoka.ini

and try again.

Pratik Shah
  • 1,782
  • 1
  • 15
  • 33
  • I have two containers when I do "docker ps -a", I enter both like 'docker exec -it da11eabd1110 bin/bash' and did curl – Srinath Ganesh Jun 18 '18 at 10:46
  • ok, then there is some issue in your docker-compose.yml, as in your nginx configuration, you've opened port 80 but in Nginx configuration , you are listening on 8000 – Pratik Shah Jun 18 '18 at 10:50
  • ok i'll check, and try your solution. Everything was working fine when I had installed nginx, uwsgi without compose using a shell script. – Srinath Ganesh Jun 18 '18 at 10:51
  • I previously tried this, but didn't make a difference – Srinath Ganesh Jun 18 '18 at 10:52
  • Try updating your upstream, instead of `0.0.0.0` use `web` – Pratik Shah Jun 18 '18 at 10:54
  • expose 8000:8000 line threw an error but 'ports:- "80:80"' worked fine – Srinath Ganesh Jun 18 '18 at 11:09
  • partially working now: http://127.0.0.1:8000/ gets me the uWSGI page. http://127.0.0.1/ gets me 502 Bad Gateway – Srinath Ganesh Jun 18 '18 at 11:14
  • Could you update your question ? with commands that you were trying to access , & what are the open ports for each of the container. because in both the docker container you've 8000 ports exposed. – Pratik Shah Jun 18 '18 at 11:16
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/173330/discussion-between-pratik-shah-and-srinath-ganesh). – Pratik Shah Jun 18 '18 at 11:40
  • thanks for the final part I had to do (this)[https://stackoverflow.com/questions/38346847/nginx-docker-container-502-bad-gateway-response] just the problem was the post was outdated so i had to do network_mode: "host" nginx service – Srinath Ganesh Jun 18 '18 at 12:12