我有一个 Ratchet 聊天服务器文件
use Ratchet\Server\IoServer;
use Ratchet\WebSocket\WsServer;
use MyAppChat\Chat;
require dirname(__DIR__) . '/vendor/autoload.php';
$server = IoServer::factory(
new WsServer(
new Chat()
)
, 26666
);
$server->run();
我使用 Websocket 连接 ws
并且工作正常
if ("WebSocket" in window) {
var ws = new WebSocket("ws://ratchet.mydomain.org:8888");
ws.onopen = function() {
// Web Socket is connected. You can send data by send() method.
ws.send("message to send");
};
ws.onmessage = function (evt) {
var received_msg = evt.data;
};
ws.onclose = function() {
// websocket is closed.
};
} else {
// the browser doesn't support WebSocket.
}
我想要安全连接,所以我尝试使用 SSL 连接但不起作用。
if ("WebSocket" in window) {
var ws = new WebSocket("wss://ratchet.mydomain.org:8888");
ws.onopen = function() {
// Web Socket is connected. You can send data by send() method.
ws.send("message to send");
};
ws.onmessage = function (evt) {
var received_msg = evt.data;
};
ws.onclose = function() {
// websocket is closed.
};
} else {
// the browser doesn't support WebSocket.
}
我的问题是如何使用 SSL 连接 websocket
有什么想法吗?
最佳答案
如果您使用的是 Apache Web 服务器(2.4 或更高版本),请在 httpd.conf 文件中启用这些模块:
将此设置添加到您的 httpd.conf 文件中
ProxyPass /wss2/ ws://ratchet.mydomain.org:8888/
当您需要 WSS 连接时,在您的 JavaScript 调用中使用此 URL:
var ws = new WebSocket("wss://ratchet.mydomain.org/wss2/NNN");
重新启动 Apache Web 服务器并确保在应用设置(telnet 主机名端口)之前您的 Ratchet 工作程序(Web 套接字连接)已打开。
关于php Ratchet websocket SSL连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16979793/