Nginx is the reverse proxy and web server in this observability stack. It handles incoming HTTP requests, serves static files, and forwards dynamic requests to the Django application.
In this stack, Nginx:
- Listens on port 80
- Serves static files directly
- Proxies dynamic requests to Django (port 9000)
- Handles media file requests
# Nginx Reverse Proxyobs-nginx:image:nginx:alpine# Nginx on Alpine Linux (small image)container_name:obs-nginxrestart:unless-stoppedports:-"80:80"# HTTP portvolumes:-./../nginx/nginx.conf:/etc/nginx/nginx.conf:ro# Config file (read-only)-static_volume:/app/staticfiles:ro# Django static files-media_volume:/app/mediafiles:ro# User uploadsdepends_on:-obs-django# Wait for Django to startnetworks:-app_network# Can proxy to Django
nginx.conf
events{worker_connections1024;}http{include/etc/nginx/mime.types;default_typeapplication/octet-stream;upstreamdjango{serverobs-django:9000;}server{listen80;server_namelocalhost;# Static files from Django collectstaticlocation/static/{alias/app/static/;}# User-uploaded media fileslocation/media/{alias/app/mediafiles/;}# Direct static files (no collectstatic needed)location/site-static/{alias/app/site_static/;}# All other requests β Djangolocation/{proxy_passhttp://django;proxy_set_headerHost$host;proxy_set_headerX-Real-IP$remote_addr;proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;proxy_set_headerX-Forwarded-Proto$scheme;proxy_read_timeout90s;}}}
# Test home pagecurl-Ihttp://localhost/
# Test static filescurl-Ihttp://localhost/static/admin/css/base.css
# Test media filescurl-Ihttp://localhost/media/
# Test proxy to Djangocurl-Ihttp://localhost/admin/
# Test if Nginx is respondingcurl-fhttp://localhost/||echo"Nginx is down"# Check Nginx statusdockerexecobs-nginxnginx-v
# Check worker processesdockerexecobs-nginxpsaux|grepnginx
Configuration Files
File
Path
Purpose
nginx.conf
nginx/nginx.conf
Nginx configuration
Integration Points
Service
Connection
Purpose
Django
Proxy to :9000
Application backend
Static files
Volume mount
Served directly
Media files
Volume mount
Served directly
Troubleshooting
502 Bad Gateway
# Check if Django is runningdockerps|grepobs-django
# Test Django directlycurlhttp://localhost:9000/
# Check Nginx logsdockerlogsobs-nginx|tail-20
# Restart bothdockercompose-fdjango_app/docker-compose.ymlrestartobs-djangoobs-nginx