问题描述
我正在尝试运行Laracvel-echo.
I am trying to run Laracvel-echo.
主机配置:
location /socket.io {
proxy_pass http://127.0.0.1:6002/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}
我用Socat捕获标题:
I catch headers with Socat:
socat -v TCP-LISTEN:6002,fork TCP:127.0.0.1:6001
在我的DEV服务器上,我发现一切正常,协议正在更改(HTTP/1.1 101交换协议):
On my DEV server, I see that everything is ok, the protocol is changing (HTTP/1.1 101 Switching Protocols):
2020/10/22 13:51:36.147102 length=175 from=0 to=174
HTTP/1.1 101 Switching Protocols\r
Upgrade: websocket\r
Connection: Upgrade\r
Sec-WebSocket-Accept: yU0AKhFOQaw5j9cQS8oq2bjx1pw=\r
Sec-WebSocket-Extensions: permessage-deflate\r
但是在PRODUCTION服务器中,我看到GET协议(GET/socket.io HTTP/1.1):
But in PRODUCTION server i see GET protocol (GET /socket.io HTTP/1.1):
2020/10/22 13:50:34.161919 length=588 from=0 to=587
GET /socket.io HTTP/1.1\r
Upgrade: websocket\r
Connection: Upgrade\r
Host: localhost:6002\r
Pragma: no-cache\r
Cache-Control: no-cache\r
Authorization: Basic YWlkYXI6MTIzMTIz\r
User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36\r
Origin: chrome-extension://pfdhoblngboilpfeibdedpjgfnlcodoo\r
Sec-WebSocket-Version: 13\r
Accept-Encoding: gzip, deflate\r
Accept-Language: ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7\r
Sec-WebSocket-Key: rq5CaFXEzZ/vWSnOJ5H3PA==\r
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits\r
我的问题与此有关:带有Laravel-echo-的WebSocket-服务器:502错误的网关NGINX问题还是我错了?
My question is related to this: WebSocket with Laravel-echo-server: 502 Bad gatewayIs the NGINX problem or am I wrong?
请帮助我!)
推荐答案
我不知道问题出在哪里,但我找到了解决方案.我做了很多更新:将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.
这篇关于Nginx为什么不将协议更改为WebSocket?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!