I'm trying to use these instructions to setup a websockets connection on my localhost apache webserver and it's not working.
I have the mod_proxy_wstunnel
and mod_proxy modules
turned on so I should have the capability of running websockets on localhost. Nowadays Apache webserver has websockets support built in. Gone of the days of installing third party websockets apache modules like Rachet.
I get this error after following the instructions in the above question.
Uncaught DOMException: Failed to execute 'send' on 'WebSocket': Still in CONNECTING state.
WebSocket connection to 'ws://socket.localhost/' failed:
I'm using apache webserver, not litespeed, lighttpd, nginx or IIS.
By the way I'm using Uniform Server.
My first attempt (in case someone comments for me to show my work)
Make sure that the following apache modules are turned on
- mod_proxy_wstunnel
- mod_proxy_modules
Edit the already existing file called httpd.conf to then insert this into it. Make sure you edit the correct file if you have duplicate file names for different apache versions
<VirtualHost *:80>
ServerName socket.localhost
ProxyRequests Off
ProxyPass "/ws2/" "ws://localhost:8546/"
ProxyPass "/wss2/" "wss://localhost:8546/"
</VirtualHost>
Test the websocket using this HTML page with inline javascript
<script type="text/javascript">
var socket = new WebSocket('ws://socket.localhost');
socket.send('Test');
</script>
Below is an example that I use for GraphQL subscription via websocket.
IP & Port are meant to be replaced by your configuration.
Make sure you have these modules installed:
Site Config:
Is my websocket endpoint. Yours might differ.