服务器发生意外响应 代码2,WebSocket连接到 失败:WebSocket握手期间出错:意外的响应代码:521...

我在连接到套接字服务器时遇到问题。

WebSocket connection to failed: Error during WebSocket handshake: Unexpected response code: 521

我有两个不同的云服务器(1)用于客户端项目,(2)用于套接字服务器。

(1)客户项目:

var token = "{{ csrf_token() }}";

window.Echo = new Echo({

broadcaster: 'socket.io',

host: "{{env('SOCKET_SERVER_HOST')}}",

origin: '*',

transports: ['websocket', 'polling', 'flashsocket', 'ws', 'wss'],

auth: {

headers: {

'X-CSRF-TOKEN' : token,

}

},

csrfToken:token,

port:"6001",

});

(2)套接字服务器

1. nginx

server {

listen 443 ssl;

listen [::]:443 ssl;

server_name mydomain.com;

error_log /var/log/nginx/proxy-error.log error;

ssl on;

ssl_certificate /etc/nginx/certs/mydomain.com.pem;

ssl_certificate_key /etc/nginx/certs/mydomain.com.key;

ssl_session_timeout 3m;

ssl_session_cache shared:SSL:50m;

ssl_protocols TLSv1.1 TLSv1.2;

ssl_ecdh_curve secp384r1;

location /socket.io {

proxy_pass http://mydomaincom:6001;

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header X-Forwarded-Proto https;

proxy_set_header X-VerifiedViaNginx yes;

proxy_read_timeout 60;

proxy_connect_timeout 60;

proxy_redirect off;

proxy_http_version 1.1;

proxy_set_header Upgrade $http_upgrade;

proxy_set_header Connection "upgrade";

proxy_cache_bypass $http_upgrade;

}

}

laravel-echo-server.json

下面是laravel-echo-server配置。

{

"authHost": "https://mydomaincom",

"authEndpoint": "/broadcasting/auth",

"clients": [

{

"appId": "xxxxxxxxxx",

"key": "yyyyyyyyyyyyyyyyyyyyyyyy"

}

],

"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/certs/mydomain.com.pem",

"sslKeyPath": "/etc/nginx/certs/mydomain.com.key",

"sslCertChainPath": "",

"sslPassphrase": "",

"subscribers": {

"http": true,

"redis": true

},

"apiOriginAllow": {

"allowCors": true,

"allowOrigin": "*",

"allowMethods": "GET, POST",

"allowHeaders": "Origin, Content-Type, X-Auth-Token, X-Requested-With, Accept, Authorization, X-CSRF-TOKEN, X-Socket-Id"

}

}

主管

这是主管配置。

[program:echo-worker]

directory=/home/user/apps/epanel

process_name=%(program_name)s_%(process_num)02d

command=laravel-echo-server start --config="ehealth-echo-server.json"

autostart=true

autorestart=true

user=user

numprocs=1

redirect_stderr=true

stdout_logfile=/home/user/apps/epanel/echo.log

2. Laravel回声服务器

注意:我使用redis和,laravel-echo-server并且效果很好。

有没有人有办法解决吗?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值