WebSockets listening on UNIX domain socket?

nginx, node.js, sockets, unix, websocket

Solution

Server side:

var http = require('http');
var WebSocketServer = require('ws').Server;
var server = http.createServer()
var wss = new WebSocketServer({ server : server});
server.listen('/tmp/server.sock')

Client side:

var ws = require('ws');
var client = new ws("ws+unix:///tmp/server.sock")
client.send('hello')

Problem

Is it possible to setup a WebSockets server behind an nginx server which handles connections on a UNIX domain socket? I currently have several WebSocket server instances on the same machine and have the problem of port sharing. All instances must be allocated a unique port. I want to avoid that and instead communicate between nginx and the WebSockets backend using UNIX domain sockets. The WebSockets library I'm using is ws (https://github.com/einaros/ws) I currently create my server like this: ``` var WebSocketServer = require('ws').Server; var wss = new WebSocketServer({host: "127.0.0.1", port: 8080}); ```

Original source