Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

437
Visualizações
Nginx: Connection client-server using Socket.io doesn't work

everyone!

I am trying to deploy my application, which uses React and NodeJs. The thing is, I'm using Socket.io for some data handling, and it works fine, but I don't understand how to make it work with Nginx.

I'm editing the Nhinx file with:

sudo nano /etc/nginx/sites-available/react

And this is the code:

server {
   server_name {my ip};
   root /root/my-app/build;
   index index.html index.htm;

   location / {
      try_files $uri /index.html =404;
   }

   location /socketio {
      proxy_pass http://localhost:9000;      
      include proxy_params;
      proxy_redirect off;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;      
      proxy_set_header Connection "Upgrade"; 
   }
}

Socked code in client:

import { io } from "socket.io-client";

let socket = io('http://159.223.113.224',{
    path: '/socketio',
});

export default socket;

Socked code in server:

"use strict";
exports.__esModule = true;
var express = require("express");
var http = require('http');
var appSocket = express();
var server = http.createServer(appSocket);

var io = require("socket.io")(server, {
    path: "/socketio",
    cors: {
        origin: "*",
        methods: ["GET", "POST"],
        allowedHeaders: ["my-custom-header"],
        credentials: true
    }
});

var rooms = require("./game/socketLogic/rooms")(io);
var gameLogic = require("./game/socketLogic/gameLogic")(io);
var teamChat = require("./game/socketLogic/teamChat")(io);
var timer = require("./game/socketLogic/timer")(io);
var lobbyChat = require("./game/socketLogic/lobbyChat")(io);

require("reflect-metadata");

var cors = require("cors");
const { type } = require("os");

appSocket.use(express.json());
appSocket.use(express.urlencoded({ extended: false }));
appSocket.use(cors());
server.listen(9000, function () {
    console.log('Server listening at port 9000.');
});

I don't know if I'm forgetting something. I also have the previous file running with pm2. When I enter to the page, the next error appears:

GET http://localhost:9000/socket.io/?EIO=4&transport=polling&t=NozbkRz net::ERR_CONNECTION_REFUSED

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I solved the problem, I didn't know that I should run "npm run build" again. I leave my answer here in case it helps someone else. Greetings!

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda