502 Bad Gateway для NGINX USWGI и приложения Django
У меня проблемы с запуском этого локально. У меня есть два контейнера в моем приложении. Приложение Django и сервер nginx. Ниже приведены файлы конфигурации и dockerfiles. Я получаю 502 на localhost:8000 и сообщение об ошибке выглядит следующим образом
2021/11/16 01:18:29 [error] 23#23: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.30.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", upstream: "uwsgi://127.0.0.1:8888", host: "localhost:8000", referrer: "http://localhost:8000/"
docker-compose.yml
version: "3.9"
services:
web:
build: .
container_name: test_deploy_web
hostname: blindspot
command: uwsgi --ini uwsgi.ini
volumes:
- .:/app/
- staticfiles:/app/static/
nginx:
build: ./nginx
container_name: test_deploy_nginx
volumes:
- staticfiles:/app/static/
ports:
- 8000:80
depends_on:
- web
volumes:
staticfiles:
app dockerfile
FROM python:3
ENV PYTHONUNBUFFERED=1
RUN mkdir /app
WORKDIR /app
RUN pip install --upgrade pip
COPY requirements.txt /app/
RUN pip install -r requirements.txt
COPY . /app
RUN python manage.py collectstatic --noinput
nginx dockerfile
FROM nginx:latest
COPY nginx.conf /etc/nginx/nginx.conf
COPY my_nginx.conf /etc/nginx/sites-available/
RUN mkdir -p /etc/nginx/sites-enabled/\
&& ln -s /etc/nginx/sites-available/my_nginx.conf /etc/nginx/sites-enabled/\
&& rm /etc/nginx/conf.d/default.conf
CMD ["nginx", "-g", "daemon off;"]
my_nginx.conf
# the upstream component nginx needs to connect to
upstream blindspot {
server 127.0.0.1:8888;
#server unix:/app/app.sock; # for a file socket
}
# configuration of the server
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name localhost;
# Django media
# location /media {
# alias /usr/src/app/static/media; # your Django project's media files - amend as required
# }
location /static {
alias /app/static/;
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass blindspot;
include uwsgi_params; # the uwsgi_params file you installed
}
}
uwsgi.ini
[uwsgi]
wsgi-file = /app/blindspot/wsgi.py
socket = 127.0.0.1:8888
master=true# maximum number of worker processes
processes = 4
threads = 2# Django's wsgi file
module = blindspot.wsgi:application
vacuum=true