Skip to content

Load Balancing

Kyle Sferrazza edited this page May 7, 2022 · 9 revisions
limit_req_zone $binary_remote_addr zone=hglimit:10m rate=1000r/s;

upstream hg {
        server rocky1;
        server rocky2;
        server rocky3;
}

upstream websocket {
        hash $binary_remote_addr;
        server rocky1;
        server rocky2;
        server rocky3;
}

server {
        location / {
                limit_req zone=hglimit burst=1000;
                proxy_pass http://hg;
                proxy_set_header Host $http_host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_redirect off;
                proxy_buffering off;
        }
        location /cable {
                limit_req zone=hglimit burst=1000;
                proxy_pass http://websocket;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "Upgrade";
                proxy_set_header Host $http_host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_redirect off;
                proxy_buffering off;
        }
}

hash $binary_remote_addr from https://www.nginx.com/blog/avoiding-top-10-nginx-configuration-mistakes/#ip_hash

Clone this wiki locally