Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
155
rated 0 times [  160] [ 5]  / answers: 1 / hits: 16870  / 7 Years ago, thu, october 26, 2017, 12:00:00

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 wss://example.com to wss://ws1.example.com.

Here is an example:
enter



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?



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);
};

More From » nginx

 Answers
37

Per the webSocket specification:



Once the client's opening handshake has been sent, the client MUST wait for a response from the server before sending any further data. The client MUST validate the server's response as follows:



  1. If the status code received from the server is not 101, the
    client handles the response per HTTP [RFC2616] procedures. In
    particular, the client might perform authentication if it
    receives a 401 status code; the server might redirect the client
    using a 3xx status code (but clients are not required to follow
    them), etc.



So, it's purely up to the client whether they want to support redirects or not and is clearly not something you can rely on unless you find in extensive testing that all relevant clients support it (which they apparently do not).


You will either have to go with something like a server-side proxy or a client-side scheme to manually move the connection to another server.


[#56100] Wednesday, October 25, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lailab

Total Points: 706
Total Questions: 102
Total Answers: 95

Location: Falkland Islands
Member since Mon, Jul 13, 2020
4 Years ago
;