我知道可以通过反向代理(如Nginx,HAproxy等)传递请求,但我需要将请求重定向到同一域后缀中的另一个公共服务器.即从wss://example.com到wss://ws1.example.com.
这是一个例子:
我需要重定向来自Nginx或Java的请求.
是否有可能组织?我是否需要在客户端处理重定向或此代码是否足够?
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);
};
解决方法:
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:
- 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.
因此,完全取决于客户是否要支持重定向,并且显然不是您可以依赖的东西,除非您在广泛的测试中发现所有相关客户都支持它(他们显然不支持).
您将不得不使用服务器端代理或客户端方案等手动将连接移动到另一台服务器.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。