Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

By KEEV
My droplet configuration: OS: Ubuntu 18.04.3 (LTS) x64 CPU: 4 core RAM : 8GB SSD: 80GB
On droplet, installed gitlab, docker, docker-compose. Deployed Django, Gunicorn, NGINX, Postgresql using Docker and GitLab CI/CD on DO droplet.
Below are configuration files:
nginx.conf
upstream keev {
server web:8000;
}
server {
listen 80;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
<^>proxy_connect_timeout 120;
proxy_send_timeout 120;
proxy_read_timeout 120;
send_timeout 120;
client_body_timeout 120;<^>
proxy_pass http://keev;
}
location /staticfiles/ {
alias /home/app/web/staticfiles/;
}
location /mediafiles/ {
alias /home/app/web/mediafiles/;
}
proxy_connect_timeout 120;
proxy_send_timeout 120;
proxy_read_timeout 120;
send_timeout 120;
client_body_timeout 120;
}
docker-compose-prod.yml
version: '3.7'
services:
# Redis
redis:
image: redis:5.0-alpine
db:
image: postgres:12-alpine
env_file:
- .env
web:
image: "${WEB_IMAGE}"
expose:
- "8000"
volumes:
- ./app:/app
- static_volume:/home/app/web/staticfiles
- media_volume:/home/app/web/mediafiles
command: sh -c "python manage.py wait_for_db &&
python manage.py migrate &&
python manage.py collectstatic --no-input --clear &&
gunicorn keev.wsgi:application --workers 8 --threads 8 -t 120 --bind 0.0.0.0:8000"
env_file:
- .env
depends_on:
- db
- redis
nginx:
image: "${NGINX_IMAGE}"
ports:
- "8001:80"
volumes:
- static_volume:/home/app/web/staticfiles
- media_volume:/home/app/web/mediafiles
depends_on:
- web
links:
- web
restart: on-failure
volumes:
static_volume:
media_volume:
Dockerfile
FROM python:3.7-alpine
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# some packages install needed
...
...
...
COPY ./requirements.txt /requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
# Setup directory structure
RUN mkdir -p /app
ENV APP_HOME=/app
RUN mkdir APP_HOME
RUN mkdir $APP_HOME/staticfiles
RUN mkdir $APP_HOME/mediafiles
WORKDIR $APP_HOME
COPY /app $APP_HOME
Dockerfile is correctly configured.
By using Gitlab CI/CD build container image and pulled on droplet and run it.
The thing is that my some request need more than 1 minute to process in my Django project. And I have already figure it out that how to increase the request timeout to 2 minutes from gunicorn and nginx but it worked on local system.
gunicorn
gunicorn keev.wsgi:application --workers 8 --threads 8 -t 120 --bind 0.0.0.0:8000
nginx
proxy_connect_timeout 120;
proxy_send_timeout 120;
proxy_read_timeout 120;
send_timeout 120;
client_body_timeout 120;
But when it deployed to droplet it didn’t work, it gives response 504 Gateway timeout after request take longer than 1 minute to process. Don’t know how it goes wrong on server. Read lot of articles and post regarding docker, nginx, django and gateway timeout.
Please need help for this, kind of stuck for this.
Thanks for helping me.
WildcatMedia
jeffs
0621335d663b4b699a60eb27e28153
accesstrax
Dwight Trumbower
admin
yimprogramming
samunyi90
1d6ce141ab5444dfb1ea2dd29cf4b1
Matt Fricker
joel9b158e40551b15093f213f