nginx配置

upstream nodes {
            ip_hash;
               server 192.168.1.114:3000;
            server 192.168.1.114:3001;
            server 192.168.1.114:3002;
}
server {
    listen 80;
    server_name ws;
    index index.html index.htm index.php;

    location /{
        proxy_pass http://nodes; #反向代理集群
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_redirect off;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

socket.io

var express = require('express');
var app = express();
var path = require('path');
var server = require('http').createServer(app);
var io = require('socket.io')(server);
var port = process.env.PORT || 3000;
server.listen(port, () => {
    console.log('Server listening at port %d', port);
});

欢迎扫描下方二维码,持续关注:

互联网工程师(id:phpstcn),我们一起学习,一起进步