简体   繁体   中英

akamai + haproxy + nodejs (socket.io )

My current application use Akamai (SSL) + HAProxy(SSL) + NodeJS ( socket.io ).

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Socket IO Testing</title>
</head>
<body>

<div>
    <h3>Request</h3>
    <span id="socketId"></span>
</div>
<div>
    <h3>Response</h3>
    <span id="responseText"></span>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.js"></script>
<script>
   var socket = io.connect("https://host_name_here");
    socket.on('ConnectionEstablished', function(data) {
        document.getElementById("socketId").innerText = JSON.stringify({socketId:socket.id,text:"Socket Connected successfully"});
        document.getElementById("responseText").innerText = "";
        console.log("Connection established successfully");
    });

    socket.io.on("connect_error",function (err) {
        console.log("Connection Error : " + err);
    });
</script>
</body>
</html>

app.js

const express = require("express");
const app = express();
const socket-io = require('socket.io');

app.use(express.static("index.html");
const server = app.listen(8000,function () {
   log.info(`express server run on port 8000`);
});
const io = socket-io.listen(server);
io.on("connection",function(){
  console.log("socket connection established ");
});

When request is come directly at HAProxy and then pass to backend server ( nodejs + socket.io ) application is able to create a websocket connection over wss.

Issue come when the request is coming on Akamai and then forward to HAProxy and then to backend server ( nodejs + socket.io ) application is throwing an error with SSL termination.

Exact error msg - WebSocket connection to 'wss://{{host_domain_name}}/socket.io/?EIO=3&transport=websocket&sid=4rBehZxSnWwPsbiXAACV' failed: Error during WebSocket handshake: Unexpected response code: 400

Unable to figure out what went wrong when request is coming on Akamai.

appreciate any help or lead.

Thanks.

There is no official documentation of Websockets on Akamai. I dont think akamai supports websocket as of now. Found this on one of the akamai's forum thread

At present, we can support WebSocket trials, but not production traffic. We will communicate a timeline for full WebSocket support soon. Current alternatives are to run your WebSocket app over Akamai's IP Application Accelerator, or simply to fall back onto long polling, which is typically built into WebSocket apps.

Akamai hasn't replied to the last comment made on that thread. (Aug'17).

I dont think this is related to SSL termination. I wasn't able to make a socket connection (ws instead of wss) even on http

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM