Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
litespeed_wiki:proxy:lsws-as-a-websocket-proxy [2018/01/19 20:12]
Jackson Zhang created
litespeed_wiki:proxy:lsws-as-a-websocket-proxy [2020/01/09 00:36] (current)
Lisa Clarke [How to Configure LSWS in cPanel as a WebSocket Proxy] Proofreading
Line 1: Line 1:
-====== How to setup LSWS as WebSocket Proxy======+====== How to Set Up LSWS as WebSocket Proxy ======
  
-===== What's WebSocket? ===== +===== What'​s ​WebSocket? ===== 
-WebSocket changes the way the Internet works: It is a protocol that allows the server and the client ​can have a bidirectional conversation. The client doesn’t just request content from the server. The server also sends content to the client whenever there’s content to be sent (without waiting to be asked). This bidirectional conversation allows for realtime web experiences. ​While HTTP tries to simulate real-time interaction at great expense (through incessant refreshing),​ WebSocket makes realtime interaction a reality. This upgrades all sorts of web applications:​ stock tickers, data center monitors, news feeds… ​But probably the most exciting feature of realtime Internet is the ability for multiple users to see and react to things they each do in real time.+WebSocket changes the way the Internet works: It is a protocol that allows the server and the client ​to have a bidirectional conversation ​where the client doesn’t just request content from the server ​but the server also sends content to the client whenever there is content to be sent (without waiting to be asked). This bidirectional conversation allows for realtime web experiences. ​Where HTTP tries to simulate real-time interaction at great expense (through incessant refreshing),​ WebSocket makes realtime interaction a reality. This upgrades all sorts of web applications:​ stock tickers, data center monitors, news feeds… ​but probably the most exciting feature of realtime Internet is the ability for multiple users to see and react to each other'​s actions ​in real time.
  
-LiteSpeed Web Server can work as WebSocket proxy. ​The following wiki explains the detailed steps on how to set this up.+LiteSpeed Web Server can work as WebSocket proxy. ​See how:
  
-===== Setup WebSocket ​backend ​===== +===== Setup WebSocket ​Backend ​===== 
-The first step is to have a WebSocket backend set up, but how to set up working WebSocket backend ​is out of this wiki's scope. You can consult ​online tutorials. One of the examples is to use Nginx backend ​running ​with [[https://​github.com/​slact/​nchan|nchan module]].+The first step is to have a working ​WebSocket backend set up. Explaining ​how to achieve this is out of this wiki's scope but there are plenty of online tutorials ​that can be consulted. One such tutorial involves using an Nginx backend with an [[https://​github.com/​slact/​nchan|nchan module]].
  
-===== Test backend ​WebSocket =====+===== Test the Backend ​WebSocket =====
  
-Assuming you have backend WebSocket up and running on port 80 at <code>​ws://​domain.com/​sub/​xx1</​code>. You will need to test it to ensure it is working. ​+Assuming you have backend WebSocket up and running on port 80 at ''​<nowiki>​ws://​domain.com/​sub/​xx1</​nowiki>'',​ you will need to test it to ensure it is working. ​
  
-There are many tools available for such testing. You can either try some online tools such as ''​https://​websocket.org/​echo.html'' ​or download chrome extension tools like [[https://​chrome.google.com/​webstore/​detail/​simple-websocket-client/​pfdhoblngboilpfeibdedpjgfnlcodoo?​hl=en|Simple WebSocket Client]]. We will use Chrome Simple WebSocket Client as an example in this wiki.+There are many tools available for such testing. You can either try some online tools such as [[https://​websocket.org/​echo.html|Echo Test]] ​or download chrome extension tools like [[https://​chrome.google.com/​webstore/​detail/​simple-websocket-client/​pfdhoblngboilpfeibdedpjgfnlcodoo?​hl=en|Simple WebSocket Client]]. We will use Chrome Simple WebSocket Client as an example in this wiki.
  
 {{ :​litespeed_wiki:​proxy:​add-websocket-proxy1.png?​600 |}} {{ :​litespeed_wiki:​proxy:​add-websocket-proxy1.png?​600 |}}
  
-It tested successfully+This screenshot shows a successful testIf it had failed, you would see a ''​Simple WebSocket Client undefined''​ error, like so:
  
-If it failed, you will see ''​Simple WebSocket Client undefined''​ error. 
 {{ :​litespeed_wiki:​proxy:​add-websocket-proxy2-testfail.png?​600 |}} {{ :​litespeed_wiki:​proxy:​add-websocket-proxy2-testfail.png?​600 |}}
  
-===== How to configure ​LSWS as WebSocket Proxy===== +===== How to Configure ​LSWS Native Virtual Host as WebSocket Proxy ===== 
-LSWS Web Console ​-> Virtual Host (Native) ​-> General ​-> Web Socket Proxy Setup+In the LSWS WebAdmin ​Console, navigate to **Virtual Host (Native) > General > Web Socket Proxy Setup** 
 {{ :​litespeed_wiki:​proxy:​add-websocket-proxy3.png?​800 |}} {{ :​litespeed_wiki:​proxy:​add-websocket-proxy3.png?​800 |}}
 {{ :​litespeed_wiki:​proxy:​add-websocket-proxy4.png?​800 |}} {{ :​litespeed_wiki:​proxy:​add-websocket-proxy4.png?​800 |}}
  
-Set up URI and address.+Configure **URI** and **Address**. The URI can be a plain URI (starting with "/"​). The **URI** can be an exact match. If a plain URI ends with a "/",​ then this WebSocket backend will include all sub-URIs under this URI, such as **/sub/** should include /sub/001, /sub/002... etc.  However, the regular expression, such as ''/​sub/​*'',​ will **not** work for WebSocket.
  
-Save and restart LSWS 
  
-===== Final Test: The Front end =====+Save and restart LSWS.
  
-Test front-end port 443 ''​wss://​example.com/​sub/​xx1''​.+===== How to Configure LSWS in cPanel as a WebSocket Proxy =====
  
-All working fine.+LSWS supports ''​ProxyPass''​ for WebSocket, used like so: 
  
-{{ :litespeed_wiki:proxy:​add-websocket-proxy5.png?​600 |}}+<​code>​ProxyPass / ws://localhost:3000/</​code>​
  
 +**Note**: This directive must be placed in an Apache vhost configuration file, not in .htaccess.
  
 +For example, for RocketChat, create two files like these, replacing ''​EXAMPLE''​ and ''​www.example.com''​ with the cPanel username and the actual domain:
 +
 +''/​etc/​apache2/​conf.d/​userdata/​ssl/​2_4/​EXAMPLE/​www.example.com/​proxy.conf''​
 +
 +''/​etc/​apache2/​conf.d/​userdata/​std/​2_4/​EXAMPLE/​www.example.com/​proxy.conf''​
 +
 +Add the following code to both files:
 +
 +<​code><​IfModule mod_rewrite.c>​
 +RewriteEngine on
 +RewriteRule (.*) http://​localhost:​3000/​$1 [P,L]
 +ProxyPass / ws://​localhost:​3000/​
 +</​IfModule></​code>​
 +
 +Rebuild the Apache configuration file, and restart LSWS:
 +
 +<​code>/​scripts/​buildhttpdconf
 +
 +/​usr/​local/​lsws/​bin/​lswsctrl restart</​code>​
 +
 +===== Final Test: The Front End =====
 +
 +Test front-end port 443 
 +
 +  wss://​example.com/​sub/​xx1
 +
 +If all is working fine you should see the following:
 +
 +{{ :​litespeed_wiki:​proxy:​add-websocket-proxy5.png?​600 |}}
  
  • Admin
  • Last modified: 2018/01/19 20:12
  • by Jackson Zhang