# occupymedia.cc edge — Cloudflare origin-pull terminator. # Mirrors the tunnel ingress: host-routed reverse proxy in front of the apps. # TLS: Let's Encrypt wildcard (dns-01). HTTP: redirect only. worker_processes auto; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; sendfile on; server_tokens off; map $http_upgrade $connection_upgrade { default upgrade; "" close; } # Lets the remote failover probe tell edge-served responses from tunnel-served. add_header X-Served-By occ-edge always; # HTTP: redirect everything to HTTPS. server { listen 80; listen [::]:80; return 301 https://$host$request_uri; } # Public apps. Origins mirror the cloudflared ingress: # app -> occ-app web:3001 api -> occ-app api:3000 # tube -> occ-tube 9000 chat -> occ-chat 6167 server { listen 443 ssl; listen [::]:443 ssl; http2 on; server_name app.occupymedia.cc; ssl_certificate /etc/letsencrypt/live/occupymedia.cc/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/occupymedia.cc/privkey.pem; client_max_body_size 2g; location / { proxy_pass http://web:3001; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_read_timeout 3600s; proxy_send_timeout 3600s; } } server { listen 443 ssl; listen [::]:443 ssl; http2 on; server_name api.occupymedia.cc; ssl_certificate /etc/letsencrypt/live/occupymedia.cc/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/occupymedia.cc/privkey.pem; client_max_body_size 2g; location / { proxy_pass http://api:3000; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_read_timeout 3600s; proxy_send_timeout 3600s; } } server { listen 443 ssl; listen [::]:443 ssl; server_name tube.occupymedia.cc; ssl_certificate /etc/letsencrypt/live/occupymedia.cc/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/occupymedia.cc/privkey.pem; client_max_body_size 0; location / { proxy_pass http://100.92.231.98:9000; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_read_timeout 3600s; proxy_send_timeout 3600s; proxy_buffering off; } } server { listen 80; listen [::]:80; server_name chat.occupymedia.cc; # Tunnel origin path: the branded client on this host, Matrix API to the homeserver. # Element redirects first-time phone visitors here before loading config. # Send them to the form rather than the separate Element app-download hero. location = /mobile_guide/ { # Preserve the browser's HTTPS origin even on the tunnel's HTTP hop. absolute_redirect off; return 302 /#/login; } location = /hub-chat-auth.css { alias /opt/occ-chat-brand/hub-chat-auth.css; default_type text/css; add_header X-Served-By occ-edge always; add_header Cache-Control "no-cache" always; } location ^~ /_matrix { proxy_pass http://100.117.210.52:6167; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto http; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_read_timeout 3600s; proxy_send_timeout 3600s; } location ^~ /.well-known/matrix/ { default_type application/json; return 200 '{"m.homeserver":{"base_url":"https://chat.occupymedia.cc"}}'; } # Hub in-app Chat: sign-in bootstrap on Element's own origin (see hub-sso/chat-sso.html). location = /hub-sso.html { alias /opt/hub-sso/chat-sso.html; default_type text/html; add_header X-Served-By occ-edge always; add_header Cache-Control "no-store" always; add_header Content-Security-Policy "default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; frame-ancestors https://app.occupymedia.cc" always; } location / { proxy_pass http://occ-element:80; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # Hash routes never reach nginx. Inject into the SPA HTML shell; the # stylesheet only targets mx_AuthPage and leaves signed-in rooms alone. proxy_set_header Accept-Encoding ""; sub_filter '' ''; sub_filter_once on; # text/html is sub_filter's default type; JSON/JS/CSS are not rewritten. proxy_read_timeout 60s; } } server { listen 443 ssl; listen [::]:443 ssl; server_name chat.occupymedia.cc; ssl_certificate /etc/letsencrypt/live/occupymedia.cc/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/occupymedia.cc/privkey.pem; location = /mobile_guide/ { absolute_redirect off; return 302 /#/login; } location = /hub-chat-auth.css { alias /opt/occ-chat-brand/hub-chat-auth.css; default_type text/css; add_header X-Served-By occ-edge always; add_header Cache-Control "no-cache" always; } location ^~ /_matrix { proxy_pass http://100.117.210.52:6167; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_read_timeout 3600s; proxy_send_timeout 3600s; } location = /.well-known/matrix/client { default_type application/json; return 200 '{"m.homeserver":{"base_url":"https://chat.occupymedia.cc"}}'; } location = /.well-known/matrix/server { default_type application/json; return 200 '{"m.server":"chat.occupymedia.cc:443"}'; } # Hub in-app Chat: sign-in bootstrap on Element's own origin (see hub-sso/chat-sso.html). location = /hub-sso.html { alias /opt/hub-sso/chat-sso.html; default_type text/html; add_header X-Served-By occ-edge always; add_header Cache-Control "no-store" always; add_header Content-Security-Policy "default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; frame-ancestors https://app.occupymedia.cc" always; } location / { proxy_pass http://occ-element:80; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; proxy_set_header Accept-Encoding ""; sub_filter '' ''; sub_filter_once on; proxy_read_timeout 60s; } } server { listen 443 ssl; listen [::]:443 ssl; server_name ping.occupymedia.cc; ssl_certificate /etc/letsencrypt/live/occupymedia.cc/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/occupymedia.cc/privkey.pem; return 200 "edge-ok"; } # Hub branding overrides for the oCIS web client: theme json + assets are # served by the edge; every other path proxies into oCIS. Also the tunnel # origin path (:80) so both ingress paths get the same branding. server { listen 80; listen [::]:80; server_name files.occupymedia.cc; location = /themes/owncloud/theme.json { default_type application/json; alias /opt/occ-brand/hub-theme.json; } location /themes/owncloud/assets/ { alias /opt/occ-brand/; } location / { proxy_pass http://192.168.13.210:9200; # Hub in-app Drive frames oCIS web from app.occupymedia.cc: framing policy # lives in oCIS csp.yaml (frame-ancestors); drop the legacy SAMEORIGIN. proxy_hide_header X-Frame-Options; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_read_timeout 3600s; proxy_send_timeout 3600s; proxy_buffering off; client_max_body_size 2g; # oCIS web's index.html carries ownCloud branding before the app mounts # (title, blue theme-color, white/blue splash) — rewrite at the edge. proxy_set_header Accept-Encoding ""; sub_filter 'ownCloud' 'Tactical Media Broadcast Hub'; sub_filter 'content="#375f7E"' 'content="#060403"'; sub_filter 'border: 1px solid #4c5f79;' 'border: 1px solid #2E2624;'; sub_filter 'border-top-color: #fff;' 'border-top-color: #FF1610;'; sub_filter '