WebSocket Not Connecting with n8n Behind OpenLiteSpeed Reverse Proxy (Docker Setup)

#1
Hi all,

I've deployed n8n (via Docker) on a VPS and placed it behind an OpenLiteSpeed (OLS) reverse proxy. The n8n editor loads at:

https://n8n.mydomain.com

However, I’m facing an issue with WebSocket connectivity. The browser console throws this error:


[WebSocketClient] Connection error:
WebSocket connection to 'wss://n8n.mydomain.com/rest/push?...' failed
Invalid WebSocket frame: RSV1 must be clear


What I’ve done so far:

n8n Docker .env:

Code:
N8N_BASIC_AUTH_ACTIVE=true
N8N_BASIC_AUTH_USER=admin
N8N_BASIC_AUTH_PASSWORD=*********
N8N_PROTOCOL=http
N8N_HOST=n8n.mydomain.com
N8N_PORT=5678
N8N_EDITOR_BASE_URL=https://n8n.mydomain.com
WEBHOOK_TUNNEL_URL=https://n8n.mydomain.com/
N8N_JWT_SECRET=*********
OpenLiteSpeed vhost config:

Code:
extProcessor n8n_backend {
  type                    proxy
  address                 http://127.0.0.1:5678
  maxConns                100
  initTimeout             60
  retryTimeout            10
  respBuffer              0
  persistConn             1
}

setEnvIf Request_URI "/rest/push" no-gzip
setEnvIf Request_URI "/rest/push" no-brotli

context /rest/push {
  type                    proxy
  handler                 n8n_backend
  uri                     /rest/push
  allowBrowse             1
  enableWebSocket         1

  extraHeaders            Connection: upgrade
  extraHeaders            Upgrade: websocket
  extraHeaders            Access-Control-Allow-Origin: *
}

context / {
  type                    proxy
  handler                 n8n_backend
  uri                     /
  allowBrowse             1
  enableWebSocket         1

  extraHeaders            Connection: upgrade
  extraHeaders            Upgrade: websocket
  extraHeaders            Access-Control-Allow-Origin: *
}

rewrite  {
  enable                  1
  rewriteCond             %{HTTPS} !=on
  rewriteRule             ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
}
Behavior:

  • HTTPS works fine
  • n8n editor loads
  • But /rest/push?... WebSocket fails to upgrade properly
  • docker logs n8n shows repeated: Invalid WebSocket frame: RSV1 must be clear


Screenshot 2025-07-02 at 2.32.10 PM.png Screenshot 2025-07-02 at 2.32.24 PM.png
 
#2
Hi Sarath,

My environment is similar, and I have the same issue.

OLS version 1.8.4 (latest as of right now)
n8n version 1.107.3 (latest as of right now)

I found out two things:
1. If you remove OLS from the flow and access <SERVER_IP>:5678 - the websocket connection works just fine.
2. If you revert to n8n version 1.86.1 - no issues there.

So I went digging, turns out version 1.0 introduced websocket as the default push method.
Documented here https://docs.n8n.io/1-0-migration-checklist/#websockets

I was able to make it work with SSE instead.

Here is my configuration:

.env for n8n:
N8N_PUSH_BACKEND=sse
N8N_HOST=domain.com
N8N_PROTOCOL=https
N8N_PORT=5678
WEBHOOK_URL=https://domain.com/
N8N_PROXY_HOPS=1
N8N_CORS_ORIGIN=domain.com

Litespeed:
extprocessor n8n {
type proxy
address 127.0.0.1:5678
maxConns 60
initTimeout 60
retryTimeout 60
respBuffer 0
}

context / {
type proxy
handler n8n
extraHeaders <<<END_extraHeaders
RequestHeader set Origin "domain.com, domain.com"
RequestHeader set X-Forwarded-Proto "https"
RequestHeader set X-Forwarded-Host "domain.com"
RequestHeader set X-Forwarded-For "%{REMOTE_ADDR}e"
END_extraHeaders

addDefaultCharset off
}

So this is a workaround if you don't require the use of websockets, it looks like OLS is blocking/compressing the connection via websocket. I've tried numerous ways to stop it, disabling gzip/brotli compression on the Vhost or Server level, included and that didn't solve it.

If anyone finds a way to make it work with websocket and OLS as reverse proxy, please let me know
 
Top