Fix error WebSocket connection to 'wss://omegae.online/ws' failed
Fix error WebSocket connection to 'wss://omegae.online/ws'
Hi everyone,
I need assistance with a WebSocket connection issue between my frontend(omegae.online) and Socket.IO(socket.omegae.online) server. Here’s a brief overview of my setup and the problem I'm facing:
Project Overview: Frontend Project:
Port: 3000 Purpose: Serves the React application. Nginx Configuration:
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
add_header X-Cache $upstream_cache_status;
proxy_connect_timeout 30s;
proxy_read_timeout 86400s;
proxy_send_timeout 30s;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /socket.io/ {
proxy_pass http://127.0.0.1:4000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /ws/ {
proxy_pass http://127.0.0.1:4000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
**Socket.IO Server: ** Port: 4000 Purpose: Handles WebSocket connections. Nginx Configuration:
location /socket.io/ {
proxy_pass http://localhost:4000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /ws/ {
proxy_pass http://localhost:4000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location / {
proxy_pass http://localhost:4000;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_buffering off;
}
Code Config Socket:
const socketIO = require("socket.io");
const http = require("http");
const express = require("express");
const cors = require("cors");
const app = express();
const server = http.createServer(app);
const io = socketIO(server, {
cors: {
origin: "*",
methods: ["GET", "POST"],
credentials: true
},
transports: ["websocket", "polling"]
});
require("dotenv").config({
path: "./.env",
});
app.use(cors());
app.use(express.json());
app.get("/", (req, res) => {
res.send("Hello world from socket server!");
});
Issue Encountered: Error Message: WebSocket connection to 'wss://omegae.online/ws' failed Steps Taken: Verified that both the frontend and Socket.IO server are running. Confirmed that the WebSocket server is listening on port 4000. Checked Nginx configurations for both the frontend and WebSocket server to ensure correct proxy settings. Used browser developer tools to inspect WebSocket errors and responses. Could you please help me diagnose and resolve this issue? If there are any additional details or configurations you need, please let me know.
Thank you for your assistance!
Please or to participate in this conversation.