apache-radio.conf.example 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # daveo-radio — reverse proxy for davidwindham.com/radio
  2. # ============================================================================
  3. #
  4. # The radio app is a long-running Node process (see radio.service.example /
  5. # ecosystem.config.cjs). It is NOT served from the web docroot like the
  6. # PHP/WordPress parts of the site — Apache proxies /radio through to node on
  7. # 127.0.0.1:3000.
  8. #
  9. # Add the block below to the EXISTING davidwindham.com <VirtualHost> (the same
  10. # one that serves WordPress). Do NOT create a new vhost for it — /radio has to
  11. # live under the main hostname so it is same-origin with the rest of the site;
  12. # that is what lets the client open its websocket with no hardcoded host, keeps
  13. # it clear of mixed-content blocking on https, and lets /embed/chrome.js (the
  14. # shared header/footer) resolve from the docroot alongside it.
  15. #
  16. # The WordPress "Radio" page moved to /online-radio, so /radio is free. WP still
  17. # issues a permanent old-slug 301 /radio -> /online-radio; Apache answers /radio
  18. # first once this proxy is in place, so it never fires — but a browser that hit
  19. # /radio before the proxy existed will have cached that 301. Hard-reload if so.
  20. #
  21. # ---------------------------------------------------------------------------
  22. # Which option? Check your Apache version first:
  23. # apachectl -v (or: apache2 -v / httpd -v)
  24. # ---------------------------------------------------------------------------
  25. #
  26. # >= 2.4.47 -> Option A. One line carries both HTTP and the websocket.
  27. # < 2.4.47 -> Option B. ProxyPass for HTTP + a mod_rewrite rule for the
  28. # websocket upgrade.
  29. #
  30. # Use ONE option, not both. Modules needed either way:
  31. # a2enmod proxy proxy_http rewrite
  32. # Option A additionally: nothing. Option B additionally: proxy_wstunnel.
  33. #
  34. # The node app must be running with BASE_PATH=/radio and TRUST_PROXY=1 — see
  35. # ecosystem.config.cjs / radio.service.example.
  36. # ===========================================================================
  37. # OPTION A — Apache 2.4.47+ (preferred)
  38. # ===========================================================================
  39. # Paste inside <VirtualHost *:443> for davidwindham.com.
  40. ProxyPreserveHost On
  41. # radio: node app mounted at /radio. Prefix kept on both sides;
  42. # BASE_PATH=/radio tells the app to expect it. upgrade=websocket carries
  43. # socket.io at /radio/socket.io (needs 2.4.47+).
  44. ProxyPass /radio http://127.0.0.1:3000/radio upgrade=websocket
  45. ProxyPassReverse /radio http://127.0.0.1:3000/radio
  46. # ===========================================================================
  47. # OPTION B — Apache < 2.4.47 (mod_rewrite fallback)
  48. # ===========================================================================
  49. # Use this INSTEAD of Option A if your Apache predates upgrade=websocket
  50. # (e.g. Ubuntu 20.04 ships 2.4.41, Debian 10 ships 2.4.38). Without it,
  51. # socket.io still works but silently degrades to HTTP long-polling.
  52. #
  53. # The RewriteRule must appear before the ProxyPass. The two RewriteConds gate it
  54. # to genuine websocket-upgrade requests only; everything else — page loads,
  55. # static assets, socket.io's HTTP long-polling — falls through to ProxyPass.
  56. ProxyPreserveHost On
  57. RewriteEngine On
  58. RewriteCond %{HTTP:Upgrade} =websocket [NC]
  59. RewriteCond %{HTTP:Connection} upgrade [NC]
  60. RewriteRule ^/radio/(.*) ws://127.0.0.1:3000/radio/$1 [P,L]
  61. ProxyPass /radio http://127.0.0.1:3000/radio
  62. ProxyPassReverse /radio http://127.0.0.1:3000/radio
  63. # ---------------------------------------------------------------------------
  64. # Notes
  65. # ---------------------------------------------------------------------------
  66. #
  67. # * /embed/chrome.js (the shared header/footer) is served by Apache from the
  68. # WordPress docroot, NOT by this app. Nothing to configure here for it — the
  69. # page loads it root-relative and it already resolves alongside /radio.
  70. # DAW_ORIGIN is a LOCAL-DEV-ONLY shim and must stay UNSET in production.
  71. #
  72. # * No trailing-slash rule is needed in Apache: the app itself 301s /radio to
  73. # /radio/ so relative asset URLs resolve.
  74. #
  75. # * The Icecast stream is a separate origin (stream.davidawindham.com) reached
  76. # directly by the browser's audio element and by this app's /api/status
  77. # proxy. Nothing to add here for it — just make sure the stream is https.