Skip to content

Commit

Permalink
Use haproxy to forward websockets (#213)
Browse files Browse the repository at this point in the history
* Use haproxy to forward websockets

* Use haproxy to proxy websockets

* Update load balancer

---------

Co-authored-by: heran yang <[email protected]>
  • Loading branch information
feiniks and heran yang authored Sep 6, 2023
1 parent abb1682 commit a2ca958
Showing 1 changed file with 37 additions and 34 deletions.
71 changes: 37 additions & 34 deletions manual/deploy_pro/notification-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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.

```
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
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;
}
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;
}
}
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.

```

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/
#/etc/haproxy/haproxy.cfg
# Other existing haproxy configurations
......
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
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
```

0 comments on commit a2ca958

Please sign in to comment.