1

I'm trying to configure Focalboard to run in a specific subdirectory using Nginx. I followed the steps from the official Focalboard documentation and was able to set it up normally. However, after moving Focalboard to the /focalboard subdirectory, the WebSocket connection started showing issues.

Nginx Configuration:

upstream focalboard {
   server localhost:8000;
   keepalive 32;
}

server {
   listen 443 ssl;
   server_name example.com;

   ssl_certificate /path/to/certificate.crt;
   ssl_certificate_key /path/to/certificate.key;
   ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
   ssl_ciphers HIGH:!aNULL:!MD5;

   # WebSocket configuration
   location /focalboard/ws/ {
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection "upgrade";
       client_max_body_size 50M;
       proxy_set_header Host $http_host;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $scheme;
       proxy_set_header X-Frame-Options SAMEORIGIN;
       proxy_buffers 256 16k;
       proxy_buffer_size 16k;
       client_body_timeout 60;
       send_timeout 300;
       lingering_timeout 5;
       proxy_connect_timeout 1d;
       proxy_send_timeout 1d;
       proxy_read_timeout 1d;
       proxy_pass http://focalboard;
   }

   # Default configuration for Focalboard
   location /focalboard/ {
       client_max_body_size 50M;
       proxy_set_header Connection "";
       proxy_set_header Host $http_host;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $scheme;
       proxy_set_header X-Frame-Options SAMEORIGIN;
       proxy_buffers 256 16k;
       proxy_buffer_size 16k;
       proxy_read_timeout 600s;
       proxy_cache_revalidate on;
       proxy_cache_min_uses 2;
       proxy_cache_use_stale timeout;
       proxy_cache_lock on;
       proxy_http_version 1.1;
       proxy_pass http://focalboard/;
   }
}

Focalboard config.json:

{
    "serverRoot": "https://example.com/focalboard",
    "port": 8000,
    "dbtype": "sqlite3",
    "dbconfig": "./focalboard.db",
    "postgres_dbconfig": "dbname=exampledb sslmode=disable",
    "useSSL": false,
    "webpath": "./pack",
    "filespath": "./files",
    "telemetry": true,
    "prometheusaddress": ":9092",
    "session_expire_time": 2592000,
    "session_refresh_time": 18000,
    "localOnly": false,
    "enableLocalMode": true,
    "localModeSocketLocation": "/var/tmp/example_local.socket"
}

After applying this configuration, I'm repeatedly getting the following error: Unexpected close, re-opening websocket

The WebSocket connection keeps closing unexpectedly and immediately reopening, which creates a constant loop.

  • Is there something wrong or missing in my Nginx WebSocket configuration?
  • How can I fix the WebSocket disconnection issue when running Focalboard in a subdirectory?

1 Answer 1

0

The proxy_pass directive within a prefix location can optionally modify the requested URL before passing it upstream. This is achieved by appending a path component to its value.

In your second block you have:

location /focalboard/ { ..., proxy_pass http://focalboard/; }

Which includes an instruction to transform /focalboard/foo to /foo, because the proxy_pass directive includes the path component /. The transformation removes /focalboard from the requested URL before passing it upstream.


In your first block you have:

location /focalboard/ws/ { ..., proxy_pass http://focalboard; }

There is no path component, there is no transformation, the requested URL is passed upstream as is.


Try changing the first block to:

location /focalboard/ws { ..., proxy_pass http://focalboard/ws; }

Which includes an instruction to transform /focalboard/ws to /ws.

2
  • 1
    It worked this way: location /focalboard/ws { proxy_pass http://focalboard/ws } If you use proxy_pass focalboard/ws (with the trailing slash), Nginx interprets this as an instruction to replace the full path /focalboard/ws/ with /ws/ before passing it to the server. This would cause issues since the Focalboard server expects the URL exactly as /focalboard/ws. Thank you for your help; it helped me better understand what was happening. You can close this issue. It’s resolved. Commented Nov 11, 2024 at 18:17
  • @siqueir4 answer updated Commented Nov 12, 2024 at 7:55

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.