Laravel Echo(服务器)套接字IO-从HTTP切换到HTTPS

时间:2019-08-19 18:14:03

标签: laravel websocket socket.io laravel-echo

我似乎无法弄清楚如何使用https启用我的websocket。 这是怎么回事:

spring:
  cloud:
    stream:
      bindings:
        ...
      default-binder: kafka

从http切换到https时,我插入了应用程序id,key,并将协议设置为https(上一个:http),并将路径设置为ssl cert和key path。

bootstrap.js中的下一个

//Laravel-echo-server.json
{
"authHost": "https://www.example.com",
"authEndpoint": "/broadcasting/auth",
"clients": [
    {
        "appId": "myapp",
        "key": "ABCDE"
    }
],
"database": "redis",
"databaseConfig": {
    "redis": {},
    "sqlite": {
        "databasePath": "/database/laravel-echo-server.sqlite"
    }
},
"devMode": true,
"host": null,
"port": "6001",
"protocol": "https",
"socketio":{},
"secureOptions": 67108864,
"sslCertPath": "/etc/nginx/ssl/www.example.com/server.crt",
"sslKeyPath": "/etc/nginx/ssl/www.example.com/server.key",
"sslCertChainPath": "",
"sslPassphrase": "",
"subscribers": {
    "http": true,
    "redis": true
},
"apiOriginAllow": {
    "allowCors": false,
    "allowOrigin": "",
    "allowMethods": "",
    "allowHeaders": ""
}
}

注意:我读了一些有关轮询和websocket的内容,因此我将传输设置为websockets,但没有做任何事情。我不妨删除它。

我认为我不会导入套接字io客户端CDN或类似

import Echo from 'laravel-echo'

window.io = require('socket.io-client');
window.Echo = new Echo({
    broadcaster: 'socket.io',
    host: 'https://' + window.location.hostname + ':6001',
    rejectUnauthorized: false,
    transports: ['websocket']
//   auth: {
//     headers: {
//       'Authorization': 'Bearer ABCDE',
//     },
//   },
});

由于它似乎无法正常工作,并且站点永远无法连接,因此无法加载。

当我连接到路线时,我得到:

<script src="//{{ Request::getHost() }}:6001/socket.io/socket.io.js"></script>

并且我的laravel echo服务器说一切正常,但我希望它输出用户已加入频道,至少尝试加入频道或其他任何信息,但它总是表示相同:

socket.io-client:url parse https://www.example.com:6001 +0ms
app.js:9266 socket.io-client new io instance for https://www.example.com:6001 +0ms
app.js:9266 socket.io-client:manager readyState closed +0ms
app.js:9266 socket.io-client:manager opening https://www.example.com:6001 +0ms
app.js:9266 engine.io-client:socket creating transport "polling" +0ms
app.js:9266 engine.io-client:polling polling +0ms
app.js:9266 engine.io-client:polling-xhr xhr poll +0ms
app.js:9266 engine.io-client:polling-xhr xhr open GET: https://www.example.com:6001/socket.io/?EIO=3&transport=polling&t=Moh3V2c +0ms
app.js:9266 engine.io-client:polling-xhr xhr data null +1ms
app.js:9266 engine.io-client:socket setting transport polling +2ms
app.js:9266 socket.io-client:manager connect attempt will timeout after 20000 +3ms
app.js:9266 socket.io-client:manager readyState opening +1ms
app.js:2109 Web Development
app.js:58005 You are running Vue in development mode.
Make sure to turn on production mode when deploying for production.
See more tips at https://vuejs.org/guide/deployment.html
app.js:2106 Current User: John Doe
app.js:2177 User: John Doe
app.js:9266 socket.io-client:manager connect attempt timed out after 20000 +20s
app.js:9266 engine.io-client:socket socket close with reason: "forced close" +20s
app.js:9266 engine.io-client:polling transport not open - deferring close +20s
app.js:9266 engine.io-client:socket socket closing - telling transport to close +1ms
app.js:9266 socket.io-client:manager connect_error +2ms
app.js:9266 socket.io-client:manager cleanup +0ms
app.js:9266 socket.io-client:manager will wait 893ms before reconnect attempt +1ms
app.js:9266 socket.io-client:manager attempting reconnect +894ms
app.js:9266 socket.io-client:manager readyState closed +0ms
app.js:9266 socket.io-client:manager opening https://www.example.com:6001 +1ms
app.js:9266 engine.io-client:socket creating transport "polling" +898ms
app.js:9266 engine.io-client:polling polling +900ms
app.js:9266 engine.io-client:polling-xhr xhr poll +21s
app.js:9266 engine.io-client:polling-xhr xhr open GET: https://www.example.com:6001/socket.io/?EIO=3&transport=polling&t=Moh3a9Q +1ms
app.js:9266 engine.io-client:polling-xhr xhr data null +1ms
app.js:9266 engine.io-client:socket setting transport polling +4ms
app.js:9266 socket.io-client:manager connect attempt will timeout after 20000 +6ms

我确实阅读并尝试了一些有关授权标头的方法,但是我似乎无法做到这一点。它是如此混乱和复杂,如果您愿意提供帮助,我将非常高兴。谢谢!

0 个答案:

没有答案