Node / Apache / Sockets custom hosting

Here’s a working setup for a Node server using a proxy with Apache that supports socket.io calls on Centos 8 custom hosting. As long as you are using a recent installation, all the apache modules needed will be loaded automatically.

Here are the directives I added to an existing virtual host in Apache (keep anything you already have setup). Replace all “3000” with the port number of your node server.

ProxyRequests On
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
RequestHeader set X-Forwarded-Proto https
ProxyPreserveHost On
RewriteEngine On
RewriteCond %{REQUEST_URI}  ^/socket.io            [NC]
RewriteCond %{QUERY_STRING} transport=websocket    [NC]
RewriteRule /(.*)           ws://localhost:3000/$1 [P,L]
Community Page
Last updated: