Ich habe das Problem mit Ratchet über SSL untersucht und habe versucht, meine Apache2 Serverkonfiguration zu aktivieren, indem ich proxy.load und proxy_wstunnel.load Mods aktiviere.Ratchet Websocket Apache2 SSL kann keine Verbindung zu PHP Websocket herstellen
ProxyPass /wss2/ ws://domain.com:8080
Die PHP-Socket-server.php Datei:
/etc/apache2/mods-enabled:
proxy.conf -> ../mods-available/proxy.conf
proxy.load -> ../mods-available/proxy.load
proxy_wstunnel.load -> ../mods-available/proxy_wstunnel.load
Ich habe die folgende Zeile am Ende meiner apache2.conf hinzugefügt
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use Websocket\SocketControl;
use Ratchet\Session\SessionProvider;
use Symfony\Component\HttpFoundation\Session\Storage\Handler;
require dirname(__DIR__) . '/vendor/autoload.php';
$memcache = new Memcache;
$memcache->connect('localhost', 11211);
$session = new SessionProvider(
new SocketControl,
new Handler\MemcacheSessionHandler($memcache)
);
$server = IoServer::factory(
new HttpServer(
new WsServer(
$session
)
),
8080
);
$server->run();
Die relevanten JS-Code, der versucht, eine Verbindung zum Socket-Server herzustellen:
var websocket = {
wsUri:"wss://domain.com/wss2/NNN",
socket:null,
cryptKey:null,
init:function(){
try {
if (typeof MozWebSocket == "function")
WebSocket = MozWebSocket;
if (websocket.socket && websocket.socket.readyState == 1)
websocket.socket.close();
websocket.socket = new WebSocket(websocket.wsUri);
websocket.socket.onopen = websocket.onopen.bind();
websocket.socket.onclose = websocket.onclose.bind();
websocket.socket.onmessage = websocket.onmessage.bind();
websocket.socket.onerror = websocket.onerror.bind();
} catch (exception) {
console.log("ERROR: " + exception);
}
},
Die Störung, die ich erhalten, wenn sie versuchen, eine Verbindung:
WebSocket connection to 'wss://domain.com/wss2/NNN' failed: Error during WebSocket handshake: Unexpected response code: 502