relay/nginx.conf
Andros Fenollosa 045e647ed2 Rewrite SSE view as async using redis.asyncio, fix nginx buffering
Sync generators blocked uvicorn's event loop preventing chunks from
being flushed. Converts to async generators with redis.asyncio so
streaming works correctly under ASGI. Adds /sse/ nginx location with
proxy_buffering off and 1h read timeout.
2026-05-19 09:18:36 +02:00

79 lines
No EOL
1.8 KiB
Nginx Configuration File

events {
worker_connections 1024;
}
http {
upstream django_app {
server django:8000;
}
server {
listen 80;
server_name _;
# Security headers
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
# Proxy settings
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;
# Timeouts
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
# SSE location - disable buffering for streaming responses
location /sse/ {
proxy_pass http://django_app;
proxy_buffering off;
proxy_cache off;
proxy_read_timeout 3600s;
gzip off;
}
# Main location
location / {
proxy_pass http://django_app;
}
# Health check endpoint
location /nginx-health {
access_log off;
return 200 "healthy\n";
add_header Content-Type text/plain;
}
}
# Basic Nginx settings
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
client_max_body_size 20M;
# Logging
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
# GZIP compression
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_proxied any;
gzip_comp_level 6;
gzip_types
text/plain
text/css
text/xml
text/javascript
application/json
application/javascript
application/xml+rss
application/atom+xml;
}