Set OLS up as a WebSocket Proxy¶
In this article we will explain how to set up a WebSocket proxy to a WebSocket backend.
With a WebSocket proxy, OpenLiteSpeed will forward traffic with the WebSocket upgrade request to the WebSocket backend specified in the WebSocket proxy. Traffic without this upgrade request can be served via a separateĀ Context.
This means you can keep your WebSocket application behind OpenLiteSpeed, both for security and efficient handling of connections. It also means you can take advantage of OpenLiteSpeed's efficient service of static or dynamic content while still having WebSocket content on the same page. For more information about WebSocket and WebSocket proxies, please seeĀ our blog.
Note
OpenLiteSpeed does not support WSS as a backend WebSocket, but the client can still use WSS over HTTPS to connect if you have SSL set up.
Have a WebSocket Backend Ready¶
Have a backend WebSocket up and running on port 7681 at ws://example.com:7681
. You can use an online tool like Echo Test or download a Chrome extension tool like Simple WebSocket Client, to make sure it's working.
Add a WebSocket Proxy to Your Virtual Host¶
Open the WebAdmin Console.
Navigate to Virtual Hosts > Example Virtual Host > WebSocket Proxy and click Add.
Set the following values:
- URI: The URI for your WebSocket application relative to your virtual host's domain. In this example, we used
/
. - Address: The IP address of the WebSocket backend. In this example, we used
127.0.0.1:7681
Save the WebSocket proxy and perform a graceful restart to apply the changes.
Verify¶
Point your browser to wherever you put the WebSocket page and your WebSocket page should come up. Or using any online WebSocket Tester to verify the connection, input Socket URL ws://192.0.2.0
(your IP address), ws://example.com
or wss://example.com
.