Use haproxy to forward websockets (#213)

* Use haproxy to forward websockets

* Use haproxy to proxy websockets

* Update load balancer

---------

Co-authored-by: heran yang <heran.yang@seafile.com>
This commit is contained in:
feiniks 2023-09-06 15:49:41 +08:00 committed by GitHub
parent abb168299e
commit a2ca9581b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,7 +2,7 @@
In Seafile Pro edition, the notification server is the same as [community edition notification server](../deploy/notification-server.md).
If you enable [clustering](./deploy_in_a_cluster.md), You need to deploy notification server on one of the servers. The reverse proxy (nginx or apache) on other front-end nodes should forward websockets requests to this node. The notification server configuration corresponding to each node of the cluster is as follows.
If you enable [clustering](./deploy_in_a_cluster.md), You need to deploy notification server on one of the servers. The load balancer should forward websockets requests to this node. The notification server configuration corresponding to each node of the cluster is as follows.
The notification server configuration should be the same as in community edition:
@ -19,41 +19,44 @@ log_level = info
jwt_private_key = M@O8VWUb81YvmtWLHGB2I_V7di5-@0p(MF*GrE!sIws23F
```
The nginx or Apache configuration of the cluster nodes should be the same, but forwarding requests to notification server node, instead of a local port.
You need to configure load balancing according to the following forwarding rules:
We generally recommend deploying notification server behind nginx, the notification server can be supported by adding the following nginx configuration:
1. Forward `/notification/ping` requests to notification server via http protocol.
2. Forward websockets requests with URL prefix `/notification` to notification server.
Here is a configuration that uses haproxy to support notification server, and haproxy version needs to be >= 2.0.
You should use similar configurations for the other load balancers.
```
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
#/etc/haproxy/haproxy.cfg
server {
location /notification/ping {
proxy_pass http://192.168.1.134:8083/ping;
access_log /var/log/nginx/notif.access.log;
error_log /var/log/nginx/notif.error.log;
}
# Other existing haproxy configurations
......
location /notification {
proxy_pass http://192.168.1.134:8083/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
access_log /var/log/nginx/notif.access.log;
error_log /var/log/nginx/notif.error.log;
}
}
frontend seafile
bind 0.0.0.0:80
mode http
option httplog
option dontlognull
option forwardfor
acl notif_ping_request url_sub -i /notification/ping
acl ws_requests url_sub -i /notification
acl hdr_connection_upgrade hdr(Connection) -i upgrade
acl hdr_upgrade_websocket hdr(Upgrade) -i websocket
use_backend ws_backend if hdr_connection_upgrade hdr_upgrade_websocket
use_backend notif_ping_backend if notif_ping_request
use_backend ws_backend if ws_requests
default_backend backup_nodes
```
Or add the configuration for Apache:
```
ProxyPass /notification/ping http://192.168.1.134:8083/ping/
ProxyPassReverse /notification/ping http://192.168.1.134:8083/ping/
ProxyPass /notification ws://192.168.1.134:8083/
ProxyPassReverse /notification ws://192.168.1.134:8083/
backend backup_nodes
cookie SERVERID insert indirect nocache
server seafileserver01 192.168.0.137:80
backend notif_ping_backend
option forwardfor
server ws 192.168.0.137:8083
backend ws_backend
option forwardfor # This sets X-Forwarded-For
server ws 192.168.0.137:8083
```