Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

434
Views
Nginx: la conexión cliente-servidor usando Socket.io no funciona

¡todo el mundo!

Estoy tratando de implementar mi aplicación, que usa React y NodeJs . El caso es que estoy usando Socket.io para el manejo de algunos datos y funciona bien, pero no entiendo cómo hacerlo funcionar con Nginx.

Estoy editando el archivo Nhinx con:

sudo nano /etc/nginx/sitios-disponibles/reaccionar

Y este es el código:

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

Código calcetín en el cliente :

 import { io } from "socket.io-client"; let socket = io('http://159.223.113.224',{ path: '/socketio', }); export default socket;

Código socked en el servidor :

 "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.'); });

No sé si me estoy olvidando de algo. También tengo el archivo anterior ejecutándose con pm2. Cuando entro a la página me aparece el siguiente error:

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

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Resolví el problema, no sabía que debía ejecutar " npm run build " nuevamente. Dejo aquí mi respuesta por si le sirve a alguien más. ¡Saludos!

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!