Please anyone can help me, I’m trying to run my django project with nginx and I faced this error.
Docker-compose file:
version: "3.8"
services:
django:
build: .
container_name: JobBoard
command: bash -c " gunicorn JobApplicationSystem.wsgi:application --bind 0.0.0.0:8000 " #&& python manage.py runserver 0.0.0.0:8000"
volumes:
- static_volume:/app/staticfiles
- media_volume:/app/mediafiles
#expose:
# - 8000
ports:
- '8000:8000'
depends_on:
- sqlserver
sqlserver:
image: mcr.microsoft.com/mssql/server
container_name: sqlserver
hostname: sqlserver
environment:
- ACCEPT_EULA=Y
- MSSQL_SA_PASSWORD=Aaaa@12345 #${SQL_DB_PASS}
ports:
- '1433:1433'
volumes:
- sqlserver-data:/var/opt/mssql
nginx:
build: ./nginx
container_name: nginx
volumes:
- static_volume:/app/staticfiles
- media_volume:/app/mediafiles
ports:
- 1337:80
depends_on:
- django
volumes:
media_volume:
static_volume:
sqlserver-data:
driver: local
Docker file :
# syntax=docker/dockerfile:1
FROM python:3.8-slim-buster
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# create the appropriate directories
ENV HOME=/app
ENV APP_HOME=/app
RUN mkdir $APP_HOME
RUN mkdir $APP_HOME/staticfiles
RUN mkdir $APP_HOME/mediafiles
WORKDIR $APP_HOME
COPY requirements5.txt ./
RUN python -m pip install --upgrade pip
RUN apt-get update \
&& apt-get -y install gcc \
&& apt-get -y install g++ \
&& apt-get -y install unixodbc \
&& apt-get install --yes --no-install-recommends \
apt-transport-https \
curl \
gnupg \
tdsodbc\
&& curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
&& curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list \
&& apt-get update \
&& ACCEPT_EULA=Y apt-get install -y msodbcsql17\
&& apt-get install -y unixodbc-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /tmp/*
RUN pip3 install -r requirements5.txt
COPY . .
nginx config file :
server {
listen 80;
server_name 127.0.0.1:8000;
location / {
#resolver 8.8.8.8;
proxy_pass http://127.0.0.1:8000; #JobApplicationSystem;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
location /static/ {
alias /app/staticfiles/;
}
location /media/ {
alias /app/mediafiles/;
}
}
nginx docker file:
FROM nginx:1.21-alpine
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hi @aref20,
The error you are facing connect() failed (111: Connection refused) while connecting to upstream is most often than not related to your Application or its configuration. This means Nginx is configured properly however the issue might be somewhere in Django’s config or code. It might be Gunicorn or Django’s config.
From the provided docker files, I don’t see anything wrong. I’ll suggest checking other error logs, of Gunicorn and Django on the exact error.