我正在尝试为CakePHP 3实现WyriHaximus/Ratchet插件。我的cakephp应用程序运行在eg: blah.myhost.com上,它启用了cakephp证书。我已经为插件配置设置了app.php,如下所示
'WyriHaximus' => [
'Ratchet' => [
'internal' => [
'address' => '0.0.0.0',
'port' => 8888,
],
'external' => [
'hostname' => 'blah.myhost.com',
'port' => 8888,
],
'defaults' => [
'retry_delay_growth' => 0.25,
],
'realm_salt' => 'y[Pw3^o`hLxn`sZkZgtIZ={?B:!Q.8',
'realm_auth_key_salt' => 'EEA~D`o:ZIIm=hR0bcD$3D+((ti:V;',
'realms' => [
'realm1' => [], // Always has to be an array
'secure' => [
'auth' => true,
'auth_key' => '5J^e=7ec5g!0j#I4.t%"0Ih2)qp]I)',
'max_retries' => 13,
],
],
],
]我可以使用here指令运行web套接字服务器,它运行得很好,并输出如下
2019-06-04T18:38:02.6496330 debug [Thruway\Peer\Router 5123] New router created
2019-06-04T18:38:02.6531680 info [Thruway\Authentication\AuthenticationManager 5123] New client created
2019-06-04T18:38:02.6550820 info [WyriHaximus\Ratchet\Websocket\InternalClient 5123] New client created
2019-06-04T18:38:02.6554090 info [WyriHaximus\Ratchet\Websocket\InternalClient 5123] New client created
2019-06-04T18:38:02.6560020 info [WyriHaximus\Ratchet\Security\AuthorizationManager 5123] New client created
2019-06-04T18:38:02.6614470 info [WyriHaximus\Ratchet\Security\JWTAuthProvider 5123] New client created
2019-06-04T18:38:02.6619220 info [Thruway\Peer\Router 5123] Starting router
2019-06-04T18:38:02.6685010 info [Thruway\RealmManager 5123] Got prehello...
2019-06-04T18:38:02.6687590 debug [Thruway\RealmManager 5123] Creating new realm 'thruway.auth'
2019-06-04T18:38:02.6719630 debug [Thruway\RealmManager 5123] Adding realm 'thruway.auth'
2019-06-04T18:38:02.6763120 debug [Thruway\Authentication\AuthenticationManager 5123] Client onMessage: [Thruway\Message\WelcomeMessage]
2019-06-04T18:38:02.6765620 info [Thruway\Authentication\AuthenticationManager 5123] We have been welcomed...
2019-06-04T18:38:02.6794560 debug [Thruway\Authentication\AuthenticationManager 5123] Client onMessage: [Thruway\Message\RegisteredMessage]
2019-06-04T18:38:02.6797150 info [Thruway\Role\Callee 5123] Setting registration_id for thruway.auth.registermethod (0)
2019-06-04T18:38:02.6814840 info [Thruway\RealmManager 5123] Got prehello...
2019-06-04T18:38:02.6817350 debug [Thruway\RealmManager 5123] Creating new realm 'realm1'
2019-06-04T18:38:02.6819770 debug [Thruway\RealmManager 5123] Adding realm 'realm1'
2019-06-04T18:38:02.6825430 debug [WyriHaximus\Ratchet\Websocket\InternalClient 5123] Client onMessage: [Thruway\Message\WelcomeMessage]
2019-06-04T18:38:02.6827820 info [WyriHaximus\Ratchet\Websocket\InternalClient 5123] We have been welcomed...
2019-06-04T18:38:02.6835090 info [Thruway\RealmManager 5123] Got prehello...
2019-06-04T18:38:02.6837500 debug [Thruway\RealmManager 5123] Creating new realm 'secure'
2019-06-04T18:38:02.6839950 debug [Thruway\RealmManager 5123] Adding realm 'secure'
2019-06-04T18:38:02.6845380 debug [WyriHaximus\Ratchet\Websocket\InternalClient 5123] Client onMessage: [Thruway\Message\WelcomeMessage]
2019-06-04T18:38:02.6847750 info [WyriHaximus\Ratchet\Websocket\InternalClient 5123] We have been welcomed...
2019-06-04T18:38:02.6852190 info [Thruway\RealmManager 5123] Got prehello...
2019-06-04T18:38:02.6856620 debug [WyriHaximus\Ratchet\Security\AuthorizationManager 5123] Client onMessage: [Thruway\Message\WelcomeMessage]
2019-06-04T18:38:02.6858990 info [WyriHaximus\Ratchet\Security\AuthorizationManager 5123] We have been welcomed...
2019-06-04T18:38:02.6875670 info [Thruway\Transport\RatchetTransportProvider 5123] Websocket listening on 0.0.0.0:8888
2019-06-04T18:38:02.6888710 info [Thruway\RealmManager 5123] Got prehello...
2019-06-04T18:38:02.6893150 debug [WyriHaximus\Ratchet\Security\JWTAuthProvider 5123] Client onMessage: [Thruway\Message\WelcomeMessage]
2019-06-04T18:38:02.6895540 info [WyriHaximus\Ratchet\Security\JWTAuthProvider 5123] We have been welcomed...
2019-06-04T18:38:02.6899420 debug [WyriHaximus\Ratchet\Security\JWTAuthProvider 5123] Client onMessage: [Thruway\Message\RegisteredMessage]
2019-06-04T18:38:02.6901870 info [Thruway\Role\Callee 5123] Setting registration_id for thruway.auth.jwt.onhello (0)
2019-06-04T18:38:02.6906900 debug [WyriHaximus\Ratchet\Security\JWTAuthProvider 5123] Client onMessage: [Thruway\Message\RegisteredMessage]
2019-06-04T18:38:02.6909310 info [Thruway\Role\Callee 5123] Setting registration_id for thruway.auth.jwt.onauthenticate (1)
2019-06-04T18:38:02.6928160 debug [Thruway\Authentication\AuthenticationManager 5123] Client onMessage: [Thruway\Message\InvocationMessage]
2019-06-04T18:38:02.6937120 debug [WyriHaximus\Ratchet\Security\JWTAuthProvider 5123] Client onMessage: [Thruway\Message\ResultMessage]
2019-06-04T18:38:02.6942790 debug [WyriHaximus\Ratchet\Security\JWTAuthProvider 5123] Authentication Method Registration Successful: jwt我的ufw状态输出如下
:~# ufw status | grep 8888
8888/tcp ALLOW Anywhere
8888/tcp (v6) ALLOW Anywhere (v6)我的ProxyPass部件的Apache ssl.conf如下所示
SSLProxyEngine On
ProxyRequests Off
ProxyPass "/wss2/" "wss://blah.myhost.com:8888/"这是我在浏览器中运行的代码,试图连接到websocket。
var conn = new WebSocket('wss://blah.myhost.com/wss2/');
conn.onopen = function(e) {
console.log("Connection established!");
};
conn.onmessage = function(e) {
console.log(e.data);
};我在apache access.log中收到此消息,但没有错误。
04/Jun/2019:17:47:56 +1200] "GET /wss2/ HTTP/1.1" 500 4577 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"在浏览器中运行了很长时间后,我得到的响应是
WebSocket connection to 'wss://blah.myhost.com/wss2/' failed: WebSocket opening handshake timed out我尝试过的其他方法包括在Apache default-ssl.conf中使用重写引擎
SSLProxyEngine On
RewriteEngine On
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule ^/ wss://blah.myhost.com:8888/ [P,L]使用此连接
var conn = new WebSocket('wss://blah.myhost.com/');这给出了完全相同的响应
同样,当我将app.php配置更改为使用外部ip 0.0.0.0以使服务器侦听0.0.0.0:8888,然后重写到wss://0.0.0.0:8888/我在尝试连接时在apache error.log上得到此错误。
[Tue Jun 04 18:27:04.089837 2019] [proxy:error] [pid 5648] (20014)Internal error (specific information not available): [client ^^^.^^^.^^^.^:^^^^] AH01084: pass request body failed to 0.0.0.0:8888 (0.0.0.0)
[Tue Jun 04 18:27:04.090047 2019] [proxy:error] [pid 5648] [client ^^^.^^^.^^^.^:^^^^] AH00898: Error during SSL Handshake with remote server returned by /我不确定我做错了什么;也许我在app.php中的配置是错误的,或者我错过了一些重要的步骤。
发布于 2019-06-05 11:30:55
解决方法是使用autobahn连接到Websocket,而不是我提供的代码。此外,我将app.php中的外部IP更改为0.0.0.0,将代理ip更改为0.0.0.0,而不是我的域名。
https://stackoverflow.com/questions/56438334
复制相似问题