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.

hello. I am running my web app constituted of
My app is running well locally, After deployement, I am getting the famous 502 bad gateway. i have the following files /etc/nginx/sites-available/web.conf
########################################### UPSTREAMS
#upstream django_upstream {
# server django:8000;
#}
#upstream nextjs_upstream {
# server frontend:3000;
#}
############################################ SERVER
server {
listen 80;
server_name domain.com www.domain.com.ca;
#server_tokens off;
location / {
try_files $uri @proxy_frontend;
}
location @proxy_frontend {
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Url-Scheme $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://localhost:3000;
#proxy_pass http://nextjs_upstream; <--- (tried this with upstrea. but not worked)
}
#---------------------- Backend ------------------------------
location /backend/api {
try_files $uri @proxy_api;
}
location /backend/api/docs {
try_files $uri @proxy_api;
}
location /admin {
try_files $uri @proxy_api;
}
location @proxy_api {
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Url-Scheme $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://localhost:8000;
# proxy_pass http://django_upstream; <--- (tried this with upstrea. but not worked)
}
location /django_static/ {
alias /app/backend/staticfiles/;
}
location /django_media/ {
alias /app/backend/mediafiles/;
}
}
and my docker-compose file is
version: '3.9'
services:
db:
build:
context: .
dockerfile: ./docker/database/Dockerfile
container_name: c-db
restart: always
volumes:
- db:/var/lib/postgresql/data
environment:
- POSTGRES_DB=${DB_NAME}
- POSTGRES_USER=${DB_USER}
- POSTGRES_PASSWORD=${DB_PASS}
django:
hostname: django
restart: always
image: i-api-prod:django-prod
container_name: c-api
build:
context: .
dockerfile: ./docker/backend/Dockerfile
volumes:
- staticfiles:/app/backend/staticfiles
- mediafiles:/app/backend/mediafiles
environment:
- DB_HOST=db
- DB_NAME=${DB_NAME}
- DB_USER=${DB_USER}
- DB_PASS=${DB_PASS}
- SECRET_KEY=${DJANGO_SECRET_KEY}
- ALLOWED_HOSTS=${DJANGO_ALLOWED_HOSTS}
expose:
- 8000
depends_on:
- db
# networks:
# - django-network
frontend:
hostname: frontend
build:
context: .
dockerfile: ./docker/frontend/Dockerfile
container_name: c-frontend
expose:
- 3000
# volumes:
# - frontend_static_assets:/app/frontend/static_assets
depends_on:
- django
volumes:
db:
staticfiles:
mediafiles:
The .env file for my project is
# Database variables
DB_NAME=dbname
DB_USER=rootuser
DB_PASS=changeme
DJANGO_SECRET_KEY=secretkey_for_production_environment
DJANGO_ALLOWED_HOSTS=localhost 0.0.0.0
# Frontend variables
API_BASE_URL="http:0.0.0.0/backend"
When I check nginx status is active(running).
2022/12/31 13:44:51 [error] 42558#42558: *62 connect() failed (111: Unknown error) while connecting to upstream, client: 31.2.136.184, server: domain.com, request: "GET /2.FKbxrpmVH1CttsoTtQEudY?O8A=bMnAfQJ7939h5tlyVuH_Uog&uS=ulh.AJJYMMaSJctgUQWEwiIZ.D&RPFsTVxAu=XkD HTTP/1.1", upstream: "http://localhost:3000/2.FKbxrpmVH1CttsoTtQEudY?O8A=bMnAfQJ7939h5tlyVuH_Uog&uS=ulh.AJJYMMaSJctgUQWEwiIZ.D&RPFsTVxAu=XkD", host: "www.ws.k12.ny.us"
and the understand that the problem is not nginx, but the connection to my backend and frontend. But I don’t know how to fix it.
KFSys
Thomas M
KFSys
Manuel Maldonado
07ffbf0c7e1b47f4b26636bc7104f4
Solomon
Jopce
JipSterk
Mireya Leon
ITTI Nepal
alunlewis
Bartek Pacia