G
G
Galdar Turin2021-07-21 12:43:27
Nginx
Galdar Turin, 2021-07-21 12:43:27

How to resolve socket io + nginx error?

NGINX writes this error "16762#16762: *1 upstream prematurely closed connection while reading response header from upstream, client: 85.XXX.XXX.167, server: call.123.ru, request: "GET /connect/?EIO =4&transport=polling&t=Nh8R_fa HTTP/1.1", upstream: " 10.7.156.236:6445/connect/?EIO=4&transport=polling... ", host: "call.123.ru", referrer: " https:// call.123.ru/ "" I have not tried any parameters for the proxy, the error remains. What could be the reason, before everything worked fine, a year later he returned to socket again and on you, he doesn’t want to.

nginx

location /connect/ {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $host;

    proxy_pass http://socket_call;

    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
  }


node server

const https             = require('https');

const server            = https.createServer().listen(6445);

const io = require("socket.io")(server, {
  "path": "/connect"
  //"wsEngine": require("eiows").Server
});


io.on("connection", (socket) => {
  
  console.log(socket.id); 
  
  socket.on("data", (data) => {

    console.log(data);

  });

  socket.on("disconnect", (data) => {

    console.log(data);

  });

});


js client

<script src="https://cdn.socket.io/4.1.2/socket.io.min.js" integrity="sha384-toS6mmwu70G0fw54EGlWWeA4z3dyJ+dlXBtSURSKN4vyRFOcxd3Bzjj/AoOwY+Rg" crossorigin="anonymous"></script>
<body>
    
    

    <script>

        const socket = io("https://call.123.ru", {path: "/connect/"});

        socket.emit("data", JSON.stringify({ 'index': '123' }))

    </script>

</body>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SagePtr, 2021-07-21
@Galdar

const https = require('https');
proxy_pass http://socket_call;
Mismatch

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question