SWeBUI支持WebSocket及TCP协议,目前负载主要使用WebSocket,可基于Header进行HASH,并使用后端支持多个连接。
基于WebSocket进行负载
upstream websocket {
hash $http_x-client-id;
server 192.168.2.105:2324;
server 192.168.2.106:2324;
}
server {
listen 2324 default_server;
listen [::]:2324 default_server;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
proxy_pass http://websocket;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header Smo-Uri $request_uri;
proxy_set_header X-Real-IP $remote_addr;
}
location /ws {
proxy_pass http://websocket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
基于WebSocket进行负载
frontend smo
bind :2324
mode http
default_backend smo_server
backend smo_server
mode http
balance hdr(x-client-id)
option forwardfor
http-request set-header X-Forwarded-Port %[dst_port]
http-request add-header X-Forwarded-Proto https if { ssl_fc }
option httpchk GET /
server sweb1 192.168.2.105:2324 cookie sweb1 check
server sweb2 192.168.2.106:2324 cookie sweb2 check