# chess-io — reverse proxy for davidwindham.com/chess # ============================================================================ # # The chess app is a long-running Node process (see chess-io.service.example). # It is NOT served from the web docroot like the PHP/WordPress parts of the # site — Apache proxies /chess through to node on 127.0.0.1:8181. # # Add the block below to the EXISTING davidwindham.com (the same # one that serves WordPress). Do NOT create a new vhost for it — /chess has to # live under the main hostname so it is same-origin with the rest of the site; # that is what lets the client open its websocket with no hardcoded host and # keeps it from tripping mixed-content blocking on https. # # This REPLACES the old chess.davidwindham.com subdomain vhost, which # root-mounted the app ("ProxyPass / http://127.0.0.1:8181/") on its own # hostname. Two differences now that it's a subpath: # - socket.io lives at /chess/socket.io, not /socket.io # - the /chess prefix is KEPT on the way to node (BASE_PATH=/chess), where the # old root mount had nothing to keep. # # --------------------------------------------------------------------------- # Which option? Check your Apache version first: # apache2 -v (or: apachectl -v / httpd -v) # --------------------------------------------------------------------------- # # >= 2.4.47 -> Option A. One line carries both HTTP and the websocket. # < 2.4.47 -> Option B. ProxyPass for HTTP + a mod_rewrite rule for the # websocket upgrade (the same technique the old subdomain vhost # used, adapted to the /chess subpath). # # Use ONE option, not both. Modules needed either way: # a2enmod proxy proxy_http rewrite # Option A additionally: nothing. Option B additionally: proxy_wstunnel. # # The node app must be running with BASE_PATH=/chess and TRUST_PROXY=1 — see # chess-io.service.example. # =========================================================================== # OPTION A — Apache 2.4.47+ (preferred) # =========================================================================== # Paste inside for davidwindham.com. ProxyPreserveHost On # chess: real-time chess on node, mounted at /chess. # Prefix kept on both sides; BASE_PATH=/chess tells the app to expect it. # upgrade=websocket carries socket.io at /chess/socket.io (needs 2.4.47+). ProxyPass /chess http://127.0.0.1:8181/chess upgrade=websocket ProxyPassReverse /chess http://127.0.0.1:8181/chess # =========================================================================== # OPTION B — Apache < 2.4.47 (mod_rewrite fallback) # =========================================================================== # Use this INSTEAD of Option A if your Apache predates upgrade=websocket # (e.g. Ubuntu 20.04 ships 2.4.41, Debian 10 ships 2.4.38). # # The RewriteRule must appear before the ProxyPass. The two RewriteConds gate # it to genuine websocket-upgrade requests only; everything else — page loads, # static assets, socket.io's HTTP long-polling — falls through to ProxyPass. # # This matches on the Upgrade/Connection headers, which is more robust than the # old "?transport=websocket" query-string test but does the same job. If you # prefer to mirror the old vhost exactly, the query-string form also works: # RewriteCond %{REQUEST_URI} ^/chess/socket.io [NC] # RewriteCond %{QUERY_STRING} transport=websocket [NC] # RewriteRule /(.*) ws://127.0.0.1:8181/$1 [P,L] ProxyPreserveHost On RewriteEngine On RewriteCond %{HTTP:Upgrade} =websocket [NC] RewriteCond %{HTTP:Connection} upgrade [NC] RewriteRule ^/chess/(.*) ws://127.0.0.1:8181/chess/$1 [P,L] ProxyPass /chess http://127.0.0.1:8181/chess ProxyPassReverse /chess http://127.0.0.1:8181/chess # --------------------------------------------------------------------------- # Notes # --------------------------------------------------------------------------- # # * /embed/chrome.js (the shared header/footer) is served by Apache from the # WordPress docroot, NOT by this app. Nothing to configure here for it — the # page loads it root-relative and it already resolves alongside /chess. # DAW_ORIGIN is a LOCAL-DEV-ONLY shim and must stay UNSET in production. # # * No trailing-slash rule is needed in Apache: the app itself 301s /chess to # /chess/ so relative asset URLs resolve. # # * Optional, from the old vhost: it served a friendly 503 page when node was # down ("ProxyPass /error/ !" + "ErrorDocument 503 /error/503.html"). Under # the main site vhost that's optional — WordPress's own error handling covers # it — but you can keep the pattern if you want a chess-specific down page. # # * Point the old chess.davidwindham.com subdomain at a redirect to # https://davidwindham.com/chess/ once this is confirmed working, so old game # links don't dead-end: # # ServerName chess.davidwindham.com # ServerAlias www.chess.davidwindham.com # Redirect permanent / https://davidwindham.com/chess/ #