Last active
June 28, 2016 22:09
-
-
Save benweet/a74c87dc2ef0add10e7aeb83f986f013 to your computer and use it in GitHub Desktop.
socket.io / engine.io load balancing with stickyness using nginx hash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Same random hash will be used during the whole session | |
var hash = Math.random().toString(36).slice(2, 10) | |
// Get absolute uri | |
var uri = document.createElement('a') | |
uri.href = '/engine.io/?hash=' + hash | |
var socket = eio(uri.href) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http { | |
upstream eio { | |
hash $arg_hash consistent; | |
server localhost:3001; | |
server localhost:3002; | |
} | |
server { | |
listen 3000; | |
location /engine.io { | |
proxy_pass http://eio; | |
proxy_http_version 1.1; | |
proxy_next_upstream error timeout invalid_header; | |
proxy_connect_timeout 2; | |
proxy_set_header Host $host; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection "upgrade"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment