1
votes

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
1
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: "0.0.0.0:8000", host: "127.0.0.1"Srinath Ganesh

1 Answers

1
votes

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.