# ============================================================================= # Example nginx edge config for ICS. # # ICS itself terminates neither TLS nor host routing: an nginx (or any other # reverse proxy) in front of it does. This file shows one working layout: # - listens on 8000 (HTTP) and 8443 (HTTPS); forward 80 and 443 to them or # change the ports # - ACME webroot in /var/www/html, certificates from certbot # - upstream `backend:8000`, reachable when the proxy container shares the # docker network named by ICS_EDGE_NETWORK (see compose.yaml) # - SPA static files from the `ics_static` volume, filled by the frontend # container on every deploy, mounted read-only at /usr/share/nginx/html # # Two host names are needed: # - ics.example.com main UI and API # - html-ics.example.com isolated origin for uploaded HTML bundles # With micro-applications on (ICS_MICROAPPS_ENABLED=true) a third one: # - *.example.net one origin per app, served by the broker, on a domain # of its own (never under the ICS domain: app code must not be same-site # with ICS); ICS_MICROAPPS_APP_HOST_SUFFIX=example.net on backend and # broker. With Cloudflare in front: Universal SSL for browsers and a # Cloudflare Origin CA certificate here, see docs/DEPLOY.md. # Replace them, then validate and reload: `nginx -t && nginx -s reload`. # ============================================================================= # ---------- Upstream ---------- upstream ics_backend { server backend:8000; } # Micro-application broker (only with ICS_MICROAPPS_ENABLED=true). # nginx resolves `broker` once, at start: after the broker container is # recreated with a new address, reload nginx (`nginx -s reload`). From nginx # 1.27.3 it can follow the address itself instead: # resolver 127.0.0.11 valid=10s; # Docker's DNS, in the http block # upstream ics_broker { zone ics_broker 64k; server broker:8080 resolve; } upstream ics_broker { server broker:8080; } # WebSocket upgrades of the app pages' realtime socket (/__ics/realtime). map $http_upgrade $connection_upgrade { default upgrade; '' close; } # ---------- ics.example.com ---------- server { listen 8000; server_name ics.example.com; server_tokens off; location ~ /.well-known/acme-challenge { allow all; root /var/www/html; } location / { return 301 https://$host$request_uri; } } server { listen 8443 ssl; server_name ics.example.com; server_tokens off; http2 on; ssl_protocols TLSv1.3; ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384; ssl_prefer_server_ciphers off; ssl_session_timeout 1d; ssl_session_cache shared:MozSSL:10m; ssl_session_tickets off; ssl_certificate /etc/letsencrypt/live/ics.example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/ics.example.com/privkey.pem; access_log /var/log/nginx/access.ics.log main; # SPA static files from the `ics_static` volume. root /usr/share/nginx/html; index index.html; # Upload cap: 100 MiB (ICS_MAX_ASSET_BYTES) plus multipart framing. client_max_body_size 110m; # Compression, in case the main nginx.conf leaves gzip off. gzip on; gzip_vary on; gzip_proxied any; gzip_comp_level 5; gzip_min_length 1024; gzip_types text/plain text/css text/xml application/json application/javascript application/xml+rss image/svg+xml; # Health probes: no auth, for monitoring and deploy smoke tests. location = /healthz { proxy_pass http://ics_backend; access_log off; } location = /readyz { proxy_pass http://ics_backend; access_log off; } # OAuth discovery belongs to the issuer's root, outside /api/. # Serve JSON here; the SPA fallback prevents MCP clients from connecting. location = /.well-known/oauth-protected-resource { proxy_pass http://ics_backend; proxy_set_header Host $host; proxy_set_header X-Forwarded-Proto $scheme; } location = /.well-known/oauth-authorization-server { proxy_pass http://ics_backend; proxy_set_header Host $host; proxy_set_header X-Forwarded-Proto $scheme; } location = /.well-known/openid-configuration { proxy_pass http://ics_backend; proxy_set_header Host $host; proxy_set_header X-Forwarded-Proto $scheme; } # The broker-facing API of micro-applications exists only on the # private network (service token); never expose it at the edge. location ^~ /api/internal/ { return 404; } # API location /api/ { proxy_pass http://ics_backend; proxy_http_version 1.1; # A client must not smuggle the broker's service credential. proxy_set_header X-ICS-Service-Token ""; 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-Host $http_host; proxy_set_header X-Forwarded-Proto $scheme; proxy_read_timeout 60s; } # Live notifications (ADR-0023): a long-lived Server-Sent Events stream. # No buffering, and a read timeout well above the 15 s keepalive. location = /api/notifications/stream { proxy_pass http://ics_backend; 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 $scheme; proxy_set_header Connection ""; proxy_buffering off; proxy_cache off; proxy_read_timeout 1h; } # Service worker of browser notifications: fixed name, must never be # cached, or a fix takes a day to reach the browsers. location = /sw.js { try_files $uri =404; add_header Cache-Control "no-cache"; } location = /manifest.webmanifest { try_files $uri =404; default_type application/manifest+json; add_header Cache-Control "no-cache"; } # Hashed Vite assets are immutable. location /assets/ { try_files $uri =404; expires 1y; add_header Cache-Control "public, immutable"; } # pdf.js run-time files (decoders, CMaps, fonts; ADR-0022), versioned by # path. A missing file must be a 404, never the SPA's index.html. location /pdfjs/ { try_files $uri =404; expires 1y; add_header Cache-Control "public, immutable"; types { application/wasm wasm; text/javascript js; application/octet-stream bcmap pfb ttf icc; } } # SPA fallback: the React router resolves paths client-side. location / { try_files $uri $uri/ /index.html; add_header Cache-Control "no-cache"; } } # ---------- html-ics.example.com (isolated HTML origin) ---------- # # Uploaded HTML bundles are served from a separate host name so their # JavaScript cannot reach the main app's cookies or origin. Every request # is rewritten to `/html` and proxied to the backend, whose /html # router checks the signed grant and serves the file from the bundle. server { listen 8000; server_name html-ics.example.com; server_tokens off; location ~ /.well-known/acme-challenge { allow all; root /var/www/html; } location / { return 301 https://$host$request_uri; } } server { listen 8443 ssl; server_name html-ics.example.com; server_tokens off; http2 on; ssl_protocols TLSv1.3; ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384; ssl_prefer_server_ciphers off; ssl_session_timeout 1d; ssl_session_cache shared:MozSSL:10m; ssl_session_tickets off; ssl_certificate /etc/letsencrypt/live/html-ics.example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/html-ics.example.com/privkey.pem; access_log /var/log/nginx/access.ics-html.log main; client_max_body_size 110m; location / { rewrite ^(.*)$ /html$1 break; proxy_pass http://ics_backend; 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-Host $http_host; proxy_set_header X-Forwarded-Proto $scheme; proxy_read_timeout 60s; } } # ---------- *.example.net (micro-applications, a domain of their own) ---------- # Every app runs on its own origin `<8-character name>.example.net` (or the # long `a--prod.example.net` of earlier releases), so # cookies, storage and CSP of one app never reach another or ICS itself. # The broker picks the app from the Host header: pass it unchanged. server { listen 8000; server_name *.example.net; server_tokens off; location / { return 301 https://$host$request_uri; } } server { listen 8443 ssl; server_name *.example.net; server_tokens off; http2 on; ssl_protocols TLSv1.3; ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384; ssl_prefer_server_ciphers off; ssl_session_timeout 1d; ssl_session_cache shared:MozSSL:10m; ssl_session_tickets off; # Behind Cloudflare: the Cloudflare Origin CA certificate for *.example.net # (SSL/TLS mode Full (strict)). Without Cloudflare: any wildcard certificate. ssl_certificate /etc/ssl/ics-apps/origin.pem; ssl_certificate_key /etc/ssl/ics-apps/origin.key; # Optional with Cloudflare: Authenticated Origin Pulls, so only Cloudflare # reaches this server block, and the visitor's address in the logs. # ssl_client_certificate /etc/ssl/ics-apps/cloudflare-origin-pull-ca.pem; # ssl_verify_client on; # set_real_ip_from ; # real_ip_header CF-Connecting-IP; access_log /var/log/nginx/access.ics-apps.log main; # App API bodies are small JSON; the broker has its own cap as well. client_max_body_size 2m; location / { proxy_pass http://ics_broker; proxy_http_version 1.1; proxy_set_header X-ICS-Service-Token ""; 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; proxy_read_timeout 30s; } # Realtime socket of app pages (ADR-0032): one long-lived WebSocket per # open page. The broker pings every 30 seconds; the long timeouts only # bound a connection both sides forgot. location = /__ics/realtime { proxy_pass http://ics_broker; proxy_http_version 1.1; proxy_set_header X-ICS-Service-Token ""; 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; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_buffering off; proxy_read_timeout 1h; proxy_send_timeout 1h; } }