M
M
MrPofix2020-10-22 17:56:14
Nginx
MrPofix, 2020-10-22 17:56:14

Why doesn't Nginx change protocol to WebSocket?

My host config:

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;
}


I check the headers exchanged by the proxy using Socat:
socat -v TCP-LISTEN:6002,fork TCP:127.0.0.1:6001
I.e. listens to 6002, intercepts headers and sends the request further to port 6001.

On the DEV server 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


But in production, the protocol does NOT change, a regular GET is transmitted (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


I tried to update Nginx to 1.19.1, the situation has not changed.
The only difference is that on the DEV server Ubuntu 18, and on the prod Ubuntu 16.

Please help. Where am I wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MrPofix, 2020-10-28
@MrPofix

I don't know what the problem is, but I found a solution.
I updated a lot: Nginx to 1.19.1, may have installed additional modules. Installed npm not globally, but locally.
And at some point it started to work as it should. I still don't understand what's wrong)
Warning: this only works if you write location /socket.io.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question