0
votes

I have a website hosted with AWS Elastic Beanstalk using an nginx proxy and have been trying to use Socket.IO, however I get an error message of Firefox can’t establish a connection to the server at wss://my-domain.com/socket.io/?EIO=3&transport=websocket&sid=WKtOGhLspneTExRLAAAB and a 400 response code when the page tries to establish the connection.

This is how the node server is created and emits events:

const express = require("express");
const app = express();

const server = app.listen(8081, () => {
    console.log("Server started on port " + port);
});
const io = require("socket.io")(server);

app.route("/api/listener").post((req, res) => {
    io.emit("response", req.body.Status);
    res.sendStatus(200);
});

This is how the client attempts to connect:

const io = require("socket.io-client");

let socket = io("https://my-domain.com");
socket.on("response", 
          function() {
              console.log("Response received");
          });

This is the configuration for my load balancer: classic load balancer config

I have tried suggestions from other similar questions, like changing the protocol to SSL and instance protocol to TCP, but that stops the site from being reachable. I do have proxy_set_header Connection "upgrade" and proxy_set_header Upgrade $http_upgrade set in my configuration for nginx.

1

1 Answers

0
votes

I found a solution to my specific situation. My previous Elastic Beanstalk environment was set up with a Classic load balancer; I've migrated my website to a new Elastic Beanstalk environment with an Application load balancer and the following configuration:

alb config