Ratchet Websocket Apache2 SSL无法连接到PHP websocket
问题描述:
一直在研究与棘轮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
答
的问题是在URL中使用的是:
wsUri:"wss://domain.com/wss2/NNN",
你可以尝试:
wsUri:"wss://domain.com/wss2",
自您在配置中链接到该网址