apache-chess.conf.example 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. # chess-io — reverse proxy for davidwindham.com/chess
  2. # ============================================================================
  3. #
  4. # The chess app is a long-running Node process (see chess-io.service.example).
  5. # It is NOT served from the web docroot like the PHP/WordPress parts of the
  6. # site — Apache proxies /chess through to node on 127.0.0.1:8181.
  7. #
  8. # Add the block below to the EXISTING davidwindham.com <VirtualHost> (the same
  9. # one that serves WordPress). Do NOT create a new vhost for it — /chess has to
  10. # live under the main hostname so it is same-origin with the rest of the site;
  11. # that is what lets the client open its websocket with no hardcoded host and
  12. # keeps it from tripping mixed-content blocking on https.
  13. #
  14. # This REPLACES the old chess.davidwindham.com subdomain vhost, which
  15. # root-mounted the app ("ProxyPass / http://127.0.0.1:8181/") on its own
  16. # hostname. Two differences now that it's a subpath:
  17. # - socket.io lives at /chess/socket.io, not /socket.io
  18. # - the /chess prefix is KEPT on the way to node (BASE_PATH=/chess), where the
  19. # old root mount had nothing to keep.
  20. #
  21. # ---------------------------------------------------------------------------
  22. # Which option? Check your Apache version first:
  23. # apache2 -v (or: apachectl -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 (the same technique the old subdomain vhost
  29. # used, adapted to the /chess subpath).
  30. #
  31. # Use ONE option, not both. Modules needed either way:
  32. # a2enmod proxy proxy_http rewrite
  33. # Option A additionally: nothing. Option B additionally: proxy_wstunnel.
  34. #
  35. # The node app must be running with BASE_PATH=/chess and TRUST_PROXY=1 — see
  36. # chess-io.service.example.
  37. # ===========================================================================
  38. # OPTION A — Apache 2.4.47+ (preferred)
  39. # ===========================================================================
  40. # Paste inside <VirtualHost *:443> for davidwindham.com.
  41. ProxyPreserveHost On
  42. # chess: real-time chess on node, mounted at /chess.
  43. # Prefix kept on both sides; BASE_PATH=/chess tells the app to expect it.
  44. # upgrade=websocket carries socket.io at /chess/socket.io (needs 2.4.47+).
  45. ProxyPass /chess http://127.0.0.1:8181/chess upgrade=websocket
  46. ProxyPassReverse /chess http://127.0.0.1:8181/chess
  47. # ===========================================================================
  48. # OPTION B — Apache < 2.4.47 (mod_rewrite fallback)
  49. # ===========================================================================
  50. # Use this INSTEAD of Option A if your Apache predates upgrade=websocket
  51. # (e.g. Ubuntu 20.04 ships 2.4.41, Debian 10 ships 2.4.38).
  52. #
  53. # The RewriteRule must appear before the ProxyPass. The two RewriteConds gate
  54. # it to genuine websocket-upgrade requests only; everything else — page loads,
  55. # static assets, socket.io's HTTP long-polling — falls through to ProxyPass.
  56. #
  57. # This matches on the Upgrade/Connection headers, which is more robust than the
  58. # old "?transport=websocket" query-string test but does the same job. If you
  59. # prefer to mirror the old vhost exactly, the query-string form also works:
  60. # RewriteCond %{REQUEST_URI} ^/chess/socket.io [NC]
  61. # RewriteCond %{QUERY_STRING} transport=websocket [NC]
  62. # RewriteRule /(.*) ws://127.0.0.1:8181/$1 [P,L]
  63. ProxyPreserveHost On
  64. RewriteEngine On
  65. RewriteCond %{HTTP:Upgrade} =websocket [NC]
  66. RewriteCond %{HTTP:Connection} upgrade [NC]
  67. RewriteRule ^/chess/(.*) ws://127.0.0.1:8181/chess/$1 [P,L]
  68. ProxyPass /chess http://127.0.0.1:8181/chess
  69. ProxyPassReverse /chess http://127.0.0.1:8181/chess
  70. # ---------------------------------------------------------------------------
  71. # Notes
  72. # ---------------------------------------------------------------------------
  73. #
  74. # * /embed/chrome.js (the shared header/footer) is served by Apache from the
  75. # WordPress docroot, NOT by this app. Nothing to configure here for it — the
  76. # page loads it root-relative and it already resolves alongside /chess.
  77. # DAW_ORIGIN is a LOCAL-DEV-ONLY shim and must stay UNSET in production.
  78. #
  79. # * No trailing-slash rule is needed in Apache: the app itself 301s /chess to
  80. # /chess/ so relative asset URLs resolve.
  81. #
  82. # * Optional, from the old vhost: it served a friendly 503 page when node was
  83. # down ("ProxyPass /error/ !" + "ErrorDocument 503 /error/503.html"). Under
  84. # the main site vhost that's optional — WordPress's own error handling covers
  85. # it — but you can keep the pattern if you want a chess-specific down page.
  86. #
  87. # * Point the old chess.davidwindham.com subdomain at a redirect to
  88. # https://davidwindham.com/chess/ once this is confirmed working, so old game
  89. # links don't dead-end:
  90. # <VirtualHost *:80>
  91. # ServerName chess.davidwindham.com
  92. # ServerAlias www.chess.davidwindham.com
  93. # Redirect permanent / https://davidwindham.com/chess/
  94. # </VirtualHost>