WebSocket with Laravel-echo-server: 502 Bad gateway
WebSocket with Laravel-echo-server: 502 Bad gateway
我一个多星期都找不到解决方案。在开发服务器上一切正常,但在生产服务器上却不行。我没力气了,求助各位同仁:)
我使用 CloudFlare 在 Socket.io 上使用 Laravel-echo-server。尝试连接时,出现错误:
WebSocketError:收到意外状态代码(502 错误网关)
Ubuntu 16.04.7 LTS,Laravel 回声服务器:1.6.1,NodeJs: v12.19.0
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后我看到:
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回显服务器是运行,我可以看到它的事件。尝试在 laravel-echo-server.json 中更改主机(127.0.0.1,localhost,null,0.0.0.0),在 nginx 代理中更改为 localhost,127.0.0.1 - 没有任何帮助。我试图在 nginx 主机中添加 upstreams,它没有帮助。
此信息也没有帮助:https://github.com/tlaverdure/laravel-echo-server/issues/273
求求你帮忙:)
我想这是你的问题。
{
"authHost": "http://localhost" // This should be your domain name
}
我不知道问题出在哪里,但我找到了解决办法。
我更新了很多:将 Nginx 更新到 1.19.1,可能安装了一些额外的模块。不是全局安装 npm,而是本地安装。
它奏效了...
注意:这仅在您编写 location /socket.io. 时有效
这肯定不是重点:"authHost": "http://localhost"
我一个多星期都找不到解决方案。在开发服务器上一切正常,但在生产服务器上却不行。我没力气了,求助各位同仁:)
我使用 CloudFlare 在 Socket.io 上使用 Laravel-echo-server。尝试连接时,出现错误: WebSocketError:收到意外状态代码(502 错误网关)
Ubuntu 16.04.7 LTS,Laravel 回声服务器:1.6.1,NodeJs: v12.19.0
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后我看到:
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回显服务器是运行,我可以看到它的事件。尝试在 laravel-echo-server.json 中更改主机(127.0.0.1,localhost,null,0.0.0.0),在 nginx 代理中更改为 localhost,127.0.0.1 - 没有任何帮助。我试图在 nginx 主机中添加 upstreams,它没有帮助。 此信息也没有帮助:https://github.com/tlaverdure/laravel-echo-server/issues/273
求求你帮忙:)
我想这是你的问题。
{
"authHost": "http://localhost" // This should be your domain name
}
我不知道问题出在哪里,但我找到了解决办法。 我更新了很多:将 Nginx 更新到 1.19.1,可能安装了一些额外的模块。不是全局安装 npm,而是本地安装。 它奏效了...
注意:这仅在您编写 location /socket.io. 时有效 这肯定不是重点:"authHost": "http://localhost"