server { listen 80; server_name _; # /health pe HTTP — pentru healthcheck fără TLS location = /health { access_log off; return 200 "healthy\n"; add_header Content-Type text/plain; } # Docker DNS pentru upstream-uri dinamice resolver 127.0.0.11 valid=30s; # ── API + auth pe HTTP simplu (aplicația mobilă pe LAN nu acceptă # certificatul self-signed; SPA-ul web rămâne pe HTTPS) ── location ^~ /api/ { set $kong_upstream didi-kong; proxy_pass http://$kong_upstream:8000; proxy_http_version 1.1; proxy_set_header Host localhost; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_read_timeout 660s; proxy_send_timeout 660s; proxy_connect_timeout 10s; } location ^~ /agent-v3/ { set $kong_upstream didi-kong; proxy_pass http://$kong_upstream:8000; proxy_http_version 1.1; proxy_set_header Host localhost; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_read_timeout 660s; proxy_send_timeout 660s; proxy_connect_timeout 10s; } location ^~ /auth/ { set $kc_upstream didi-keycloak; proxy_pass http://$kc_upstream:8080; proxy_http_version 1.1; 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 http; proxy_set_header X-Forwarded-Port 80; proxy_buffer_size 128k; proxy_buffers 4 256k; proxy_busy_buffers_size 256k; } location / { return 301 https://$host$request_uri; } } server { listen 443 ssl; server_name _; http2 on; # Self-signed cert (Keycloak PKCE cere Web Crypto = secure context) ssl_certificate /etc/nginx/ssl/server.crt; ssl_certificate_key /etc/nginx/ssl/server.key; ssl_protocols TLSv1.2 TLSv1.3; root /usr/share/nginx/html; index index.html; # Upload-uri mari (video până la 500MB) client_max_body_size 500M; # Gzip compression gzip on; gzip_vary on; gzip_min_length 1024; gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml+rss application/javascript application/json; # Security headers add_header X-Frame-Options "SAMEORIGIN" always; add_header X-Content-Type-Options "nosniff" always; add_header X-XSS-Protection "1; mode=block" always; add_header Referrer-Policy "no-referrer-when-downgrade" always; # Docker DNS — upstream-urile se rezolvă dinamic (rezistă la restart de containere) resolver 127.0.0.11 valid=30s; # ============================================================ # Same-origin către stack-ul local (didi-network): # /api/* -> Kong (rutele Kong sunt host-bound; trimitem Host: localhost) # /agent-v3/* -> Kong # /auth/* -> Keycloak (prefixul /auth e nativ în instalare) # ============================================================ location ^~ /api/ { set $kong_upstream didi-kong; proxy_pass http://$kong_upstream:8000; proxy_http_version 1.1; proxy_set_header Host localhost; 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 https; proxy_set_header X-Forwarded-Host $host; # Procesarea video poate dura până la 11 min proxy_read_timeout 660s; proxy_send_timeout 660s; proxy_connect_timeout 10s; } location ^~ /agent-v3/ { set $kong_upstream didi-kong; proxy_pass http://$kong_upstream:8000; proxy_http_version 1.1; proxy_set_header Host localhost; 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 https; proxy_set_header X-Forwarded-Host $host; proxy_read_timeout 660s; proxy_send_timeout 660s; proxy_connect_timeout 10s; } location ^~ /auth/ { set $kc_upstream didi-keycloak; proxy_pass http://$kc_upstream:8080; proxy_http_version 1.1; 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 https; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Port 443; # Buffere pentru headerele mari Keycloak (JWT) proxy_buffer_size 128k; proxy_buffers 4 256k; proxy_busy_buffers_size 256k; } # Cache static assets location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { expires 1y; add_header Cache-Control "public, immutable"; } # Main application — SPA fallback (catch-all LAST) location / { try_files $uri $uri/ /index.html; } # Health check endpoint location = /health { access_log off; return 200 "healthy\n"; add_header Content-Type text/plain; } # Error pages error_page 404 /index.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } }