From a2ca9581b781e6924619d19371c74fc4da05c5d7 Mon Sep 17 00:00:00 2001 From: feiniks <36756310+feiniks@users.noreply.github.com> Date: Wed, 6 Sep 2023 15:49:41 +0800 Subject: [PATCH] Use haproxy to forward websockets (#213) * Use haproxy to forward websockets * Use haproxy to proxy websockets * Update load balancer --------- Co-authored-by: heran yang --- manual/deploy_pro/notification-server.md | 67 +++++++++++++----------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/manual/deploy_pro/notification-server.md b/manual/deploy_pro/notification-server.md index bf01d5bc..8ade50a8 100644 --- a/manual/deploy_pro/notification-server.md +++ b/manual/deploy_pro/notification-server.md @@ -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 ```