title: Is it possible to seamlessly redirect websockets?
body: <p>I know that it is possible to pass requests through the reverse proxy (like Nginx, HAproxy and so on) but I need to redirect requests to another public server in the same domain suffix. I.e. from <code>wss://example.com</code> to <code>wss://ws1.example.com</code>.<br>
  Here is an example:
  <a href="https://i.stack.imgur.com/KzRHQ.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/KzRHQ.jpg" alt="enter image description here"></a></p>
  
  <p>I need to redirect requests from Nginx or Java.
  Is to possible to organize? Do I need to handle redirects on a client side or this code is enough? </p>
  
  <pre><code>var socket = new WebSocket("wss://example.com");
  
  socket.onopen = function() {
    alert("Connection established.");
  };
  
  socket.onclose = function(event) {
    alert('Connection closed');
  };
  
  socket.onmessage = function(event) {
    alert("Data: " + event.data);
  };
  
  socket.onerror = function(error) {
    alert("Error " + error.message);
  };
  </code></pre>