#!/usr/bin/env bash # Template (copy to apache.sh, not in git, and use your own hosts). Writes /etc/apache2/sites-available/overlay.example.conf and reloads Apache. # Run on the VPS: bash apache.sh set -e CONF=/etc/apache2/sites-available/overlay.example.conf sudo tee "$CONF" > /dev/null << 'EOF' # ── overlay.example.com + heystreamer.example.com + stats.example.com ─────── # stats.example.com = the public stats page (the app serves ONLY that page on this host). # Its certificate: sudo certbot certonly --apache --cert-name example.com --expand -d -d stats.example.com # HTTP: redirect everything to HTTPS ServerName overlay.example.com ServerAlias heystreamer.example.com stats.example.com RewriteEngine on RewriteCond %{SERVER_NAME} =heystreamer.example.com [OR] RewriteCond %{SERVER_NAME} =stats.example.com [OR] RewriteCond %{SERVER_NAME} =overlay.example.com RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent] ErrorLog ${APACHE_LOG_DIR}/example.com/overlay.error.log CustomLog ${APACHE_LOG_DIR}/example.com/overlay.access.log combined # HTTPS: proxy to Node on port 3000 ServerName overlay.example.com ServerAlias heystreamer.example.com stats.example.com ProxyPreserveHost On # Tell Express it's behind HTTPS so secure session cookies work RequestHeader set X-Forwarded-Proto "https" Header always unset Content-Security-Policy Header always set Content-Security-Policy "default-src 'self' 'unsafe-inline' 'unsafe-eval' https: wss: data:;" # WebSocket must be listed before the catch-all ProxyPass /ws/overlay ws://127.0.0.1:3000/ws/overlay ProxyPassReverse /ws/overlay ws://127.0.0.1:3000/ws/overlay ProxyPass / http://127.0.0.1:3000/ ProxyPassReverse / http://127.0.0.1:3000/ ErrorLog ${APACHE_LOG_DIR}/example.com/overlay.error.log CustomLog ${APACHE_LOG_DIR}/example.com/overlay.access.log combined Include /etc/letsencrypt/options-ssl-apache.conf SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem EOF echo "==> Enabling required modules..." sudo a2enmod proxy proxy_http proxy_wstunnel headers rewrite echo "==> Enabling site..." sudo a2ensite overlay.example.conf echo "==> Testing config..." sudo apachectl configtest echo "==> Reloading Apache..." sudo systemctl reload apache2 echo "Done. Try logging in at https://overlay.example.com"