|
| 1 | +# /etc/nginx/nginx.conf (collab / develop image) |
| 2 | +# |
| 3 | +# Superset of nginx.conf: in addition to serving the static SPA it reverse- |
| 4 | +# proxies the bundled Y.js collab backend (node, listening on 127.0.0.1:1234) |
| 5 | +# so collaboration rides the same origin/port as the app. The frontend is built |
| 6 | +# with VITE_COLLAB_URL=<scheme>://<host>/collab, so: |
| 7 | +# - WebSocket sessions hit /collab/<docId> -> node /<docId> |
| 8 | +# - the pre-flight health check hits /health -> node /health |
| 9 | +# The collab server is never exposed directly; only port 80 is published. |
| 10 | + |
| 11 | +# njs dynamic module — bundled with the official nginx:alpine image. |
| 12 | +# Required for the /raw endpoint that serves decoded UVL content to UVLHub. |
| 13 | +load_module modules/ngx_http_js_module.so; |
| 14 | + |
| 15 | +events { |
| 16 | + worker_connections 1024; |
| 17 | +} |
| 18 | + |
| 19 | +http { |
| 20 | + include /etc/nginx/mime.types; |
| 21 | + default_type application/octet-stream; |
| 22 | + |
| 23 | + sendfile on; |
| 24 | + keepalive_timeout 65; |
| 25 | + |
| 26 | + js_path "/etc/nginx/njs/"; |
| 27 | + js_import raw from raw.js; |
| 28 | + |
| 29 | + # Bundled collab (Y.js websocket) server. |
| 30 | + upstream collab_backend { |
| 31 | + server 127.0.0.1:1234; |
| 32 | + } |
| 33 | + |
| 34 | + server { |
| 35 | + listen 80; |
| 36 | + server_name localhost; |
| 37 | + |
| 38 | + root /usr/share/nginx/html; |
| 39 | + index index.html; |
| 40 | + |
| 41 | + # Decodes a base64 UVL model from ?model= and returns it as plain text |
| 42 | + # so that UVLHub can fetch the raw UVL content server-side. |
| 43 | + location /raw { |
| 44 | + js_content raw.handler; |
| 45 | + } |
| 46 | + |
| 47 | + # Collab WebSocket sessions. Trailing slash strips the /collab/ prefix |
| 48 | + # so the doc id reaches the Y.js server as its room name (/<docId>). |
| 49 | + location /collab/ { |
| 50 | + proxy_pass http://collab_backend/; |
| 51 | + proxy_http_version 1.1; |
| 52 | + proxy_set_header Upgrade $http_upgrade; |
| 53 | + proxy_set_header Connection "upgrade"; |
| 54 | + proxy_set_header Host $host; |
| 55 | + proxy_set_header X-Real-IP $remote_addr; |
| 56 | + proxy_read_timeout 3600s; |
| 57 | + proxy_send_timeout 3600s; |
| 58 | + } |
| 59 | + |
| 60 | + # Health probe the frontend pings before opening a session. |
| 61 | + location = /health { |
| 62 | + proxy_pass http://collab_backend/health; |
| 63 | + proxy_set_header Host $host; |
| 64 | + } |
| 65 | + |
| 66 | + location / { |
| 67 | + try_files $uri /index.html; |
| 68 | + } |
| 69 | + |
| 70 | + gzip on; |
| 71 | + gzip_types text/css application/javascript application/json image/svg+xml; |
| 72 | + gzip_min_length 1000; |
| 73 | + } |
| 74 | +} |
0 commit comments