问题描述
我找不到解决方案已有一个多星期了.一切在开发服务器上都可以正常运行,但在生产环境上却无法正常运行.我没有力量,同事们,我呼吁您:)
I can't find a solution for more than a week. Everything works fine on the dev server, but not on production. I have no strength, I appeal to you, colleagues :)
我正在使用CloudFlare在Socket.io上使用Laravel-echo-server.尝试连接时,出现错误: WebSocketError:收到了意外的状态代码(502错误的网关)
I'm using Laravel-echo-server on Socket.io using CloudFlare. When trying to connect, I get an error:WebSocketError: Unexpected status code received (502 Bad Gateway)
Ubuntu 16.04.7 LTS, Laravel Echo Server :1.6.1, NodeJs :v12.19.0
Ubuntu 16.04.7 LTS, Laravel Echo Server: 1.6.1, NodeJs: v12.19.0
laravel-echo-server.json:
laravel-echo-server.json:
{
"authHost": "http://localhost",
"authEndpoint": "/broadcasting/auth",
"clients": [
{
"appId": "...",
"key": "..."
}
],
"database": "redis",
"databaseConfig": {
"redis": {
"password": "...",
"port": "...",
"db": 0
},
"sqlite": {}
},
"devMode": true,
"host": "",
"port": "6001",
"protocol": "http",
"socketio": {
"transports": ["websocket", "polling"]
},
"secureOptions": 67108864,
"sslCertPath": "",
"sslKeyPath": "",
"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"
}
}
Nginx主机:
server {
listen 8443 ssl;
server_name domain.tld;
ssl_certificate /etc/nginx/ssl/my.crt;
ssl_certificate_key /etc/nginx/ssl/my.key;
error_log /var/log/nginx/domain.tld/ws.log info;
location /ws {
proxy_pass http://127.0.0.1:6001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
}
启动EchoServer之后,我看到:
After start EchoServer i see:
L A R A V E L E C H O S E R V E R
version 1.6.1
⚠ Starting server in DEV mode...
✔ Running at localhost on port 6001
✔ Channels are ready.
✔ Listening for http events...
✔ Listening for redis events...
Server ready!
好,下一个:
$ curl 127.0.0.1:6001
> OK
下一步:
websocat wss://domain.tld:8443/ws
我得到了错误:
websocat: WebSocketError: Received unexpected status code (502 Bad Gateway)
Laravel回显服务器正在运行,我可以看到其事件.尝试将nginx代理中的laravel-echo-server.json(127.0.0.1,localhost,null,0.0.0.0)中的主机更改为 localhost,127.0.0.1 -没有任何帮助.我试图在Nginx主机中添加上游,但这没有帮助.此信息也无济于事: https://github.com/tlaverdure/laravel-echo-server/issues/273
Laravel echo server is running, I can see its events. Tried changing the host in laravel-echo-server.json (127.0.0.1, localhost, null, 0.0.0.0), in nginx proxy to localhost, 127.0.0.1 - nothing helps. I tried to add upstreams in nginx host, it doesn't help.This information also did not help: https://github.com/tlaverdure/laravel-echo-server/issues/273
请帮助:)
推荐答案
我不知道问题出在哪里,但我找到了解决方案.我做了很多更新:将Nginx更新为1.19.1,可能安装了一些其他模块.npm不是全局安装的,而是本地安装的.而且有效...
I don't know what the problem is, but I found a solution.I've updated a lot: updated Nginx to 1.19.1, possibly installed some additional modules. Installed npm not globally, but locally.And it worked ...
注意:仅当您编写 location/socket.io时,此功能才起作用.那不是确定的重点:"authHost":"http://localhost"
Attention: this only works if you write location /socket.io.That was not the point for sure: "authHost": "http://localhost"
这篇关于带Laravel-echo-server的WebSocket:502错误的网关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!