0
一直在研究與棘輪SSL問題,並試圖通過啓用proxy.load和proxy_wstunnel.load mods來使我的Apache2服務器配置工作。Ratchet Websocket Apache2 SSL無法連接到PHP websocket
/etc/apache2/mods-enabled:
proxy.conf -> ../mods-available/proxy.conf
proxy.load -> ../mods-available/proxy.load
proxy_wstunnel.load -> ../mods-available/proxy_wstunnel.load
我添加下面一行到我的apache2.conf結束:
ProxyPass /wss2/ ws://domain.com:8080
PHP的插座server.php文件:
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();
相關試圖連接到套接字服務器的JS代碼:
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);
}
},
嘗試連接時我收到的錯誤:
WebSocket connection to 'wss://domain.com/wss2/NNN' failed: Error during WebSocket handshake: Unexpected response code: 502