Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

439
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda