From d3f14aeb78da1a1c482184019bba82d18bf03810 Mon Sep 17 00:00:00 2001 From: Amirhossein Khalili Date: Sat, 25 Apr 2026 17:19:14 +0330 Subject: [PATCH] feat(deployment): support sse notification streaming --- README.md | 8 ++++++++ nginx/nginx.conf | 43 ++++++++++++++++++++++++++++++------------- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 1fb0d85..029b579 100644 --- a/README.md +++ b/README.md @@ -31,3 +31,11 @@ docker compose up --build ``` The backend container runs database migrations and `collectstatic` on startup, then serves Django with Gunicorn using `config.wsgi:application`. + +## SSE Notifications + +Notifications now use Server-Sent Events at `/api/notifications/stream/`. + +- Nginx disables buffering and cacheing for the SSE endpoint. +- The current Gunicorn setup can serve SSE for MVP traffic, but each live stream consumes a worker while connected. +- If notification concurrency grows, move the SSE endpoint to an async worker class or a dedicated ASGI process. diff --git a/nginx/nginx.conf b/nginx/nginx.conf index b5103fc..fd1b9b9 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -30,21 +30,38 @@ server { proxy_set_header X-Forwarded-Proto $scheme; } - # Standard API Proxy - location /api/ { - proxy_pass http://backend:8000; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - } + # Standard API Proxy + location /api/notifications/stream/ { + proxy_pass http://backend:8000; + proxy_http_version 1.1; + proxy_buffering off; + proxy_cache off; + proxy_read_timeout 3600s; + proxy_send_timeout 3600s; + proxy_set_header Connection ""; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + add_header X-Accel-Buffering no; + } + + location /api/ { + proxy_pass http://backend:8000; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } # Admin Panel Proxy - location /admin/ { - proxy_pass http://backend:8000; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - } + location /admin/ { + proxy_pass http://backend:8000; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } # Frontend Proxy location / {