Websockets and nginx

Describe the problem/error/question

The frontend is not updating due to a WebSocket error caused by Nginx. Without Nginx, the frontend updates correctly when I start a workflow.

Please, help me. I can’t take it anymore.

Translated by ChatGPT

What is the error message (if any)?

n8n logs

2025-01-26T21:06:00.026Z | debug | Querying database for waiting executions {"scopes":["waiting-executions"],"file":"wait-tracker.js","function":"getWaitingExecutions"}
2025-01-26T21:06:06.570Z | debug | Skipped browserId check on /rest/push {"file":"auth.service.js","function":"resolveJwt"}
2025-01-26T21:06:14.595Z | debug | Skipped browserId check on /rest/push {"file":"auth.service.js","function":"resolveJwt"}
2025-01-26T21:06:23.504Z | debug | Skipped browserId check on /rest/push {"file":"auth.service.js","function":"resolveJwt"}
2025-01-26T21:06:32.506Z | debug | Skipped browserId check on /rest/push {"file":"auth.service.js","function":"resolveJwt"}
2025-01-26T21:06:41.506Z | debug | Skipped browserId check on /rest/push {"file":"auth.service.js","function":"resolveJwt"}

nginx log

[26/Jan/2025:21:19:34 +0000] "GET /rest/push?pushRef=tpp1fqb0zc HTTP/1.1" 401 12 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36" "-"

chrome log

WebSocket connection to 'wss://n8n.exemple.com/rest/push?pushRef=tpp1fqb0zc' failed: 

Please share your workflow (just test workflow)

nginx config

server {
    listen 443 ssl;

    server_name n8n.exemple.com;

    ssl_certificate /etc/letsencrypt/live/n8n.exemple.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/n8n.exemple.com/privkey.pem;
    ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
    add_header Strict-Transport-Security "max-age=31536000; includeSubdomains";

    client_max_body_size 0;

    #enable for Authelia
    #include /config/nginx/authelia-server.conf;

    location / {
        #enable for Authelia
        #include /config/nginx/authelia-location.conf;
  
        proxy_pass http://n8n:5678;
	proxy_set_header Upgrade $http_upgrade; # Added for WebSocket
	proxy_set_header Connection “Upgrade”; # Modified for WebSocket
	proxy_set_header Host $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;
	chunked_transfer_encoding off;
	proxy_buffering off;
	proxy_cache off;
    }
}

n8n docker config

services:
  n8n-db:
    image: postgres:16
    restart: always
    container_name: n8n-db
    networks:
      - n8n
    environment:
      - POSTGRES_USER
      - POSTGRES_PASSWORD
      - POSTGRES_DB
      - POSTGRES_NON_ROOT_USER
      - POSTGRES_NON_ROOT_PASSWORD
    volumes:
      - ./db_storage:/var/lib/postgresql/data
      - ./init-data.sh:/docker-entrypoint-initdb.d/init-data.sh
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -h localhost -U ${POSTGRES_USER} -d ${POSTGRES_DB}']
      interval: 5s
      timeout: 5s
      retries: 10

  n8n:
    image: docker.n8n.io/n8nio/n8n
    restart: always
    container_name: n8n
    environment:
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=n8n-db
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_DATABASE=${POSTGRES_DB}
      - DB_POSTGRESDB_USER=${POSTGRES_NON_ROOT_USER}
      - DB_POSTGRESDB_PASSWORD=${POSTGRES_NON_ROOT_PASSWORD}
      - GENERIC_TIMEZONE="Europe/Brussels"
      - TZ="Europe/Brussels"
      - N8N_HOST=n8n.exemple.com
      - "WEBHOOK_URL=https://n8n.exemple.com/"
      #- "WEBHOOK_TUNNEL_URL=https://n8n.exemple.com/"
      #- N8N_PROTOCOL=https
      - N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true
      #- N8N_PUSH_BACKEND=websocket
      #- N8N_PROXY_HOPS=1
      - N8N_LOG_LEVEL=debug
      #- N8N_SECURE_COOKIE=false
    #ports:
    #  - 5678:5678
    networks:
      - nginx_nginx
      - n8n
      - llm
    volumes:
      - ./n8n_storage:/home/node/.n8n
    depends_on:
      n8n-db:
        condition: service_healthy
      n8n-qdrant:
        condition: service_healthy

  n8n-qdrant:
    image: qdrant/qdrant
    container_name: n8n-qdrant
    restart: always
    expose:
      - 6333
    networks:
      - n8n
      - nginx_nginx
    environment:
      - QDRANT__SERVICE__API_KEY=secret
    volumes:
      - ./qdrant_storage:/qdrant/storage
    healthcheck:
      test:
        - CMD-SHELL
        - bash -c ':> /dev/tcp/127.0.0.1/6333' || exit 1
      interval: 5s
      timeout: 5s
      retries: 3
networks:
  nginx_nginx:
    external: true
  llm:
    name: llm
    external: true
  n8n:
    name: n8n

Information on your n8n setup

  • n8n version: 1.75.2
  • Database (default: SQLite): PostgreSQL
  • n8n EXECUTIONS_PROCESS setting (default: own, main): ?
  • Running n8n via (Docker, npm, n8n cloud, desktop app): docker
  • Operating system: Ubuntu 24.04

Hi @maxencevm

Thanks for posting here and welcome to the community! :cupcake:

try adding proxy_http_version 1.1 to your nginx config as well.
If you’re using any browser extensions that might interfere with WebSocket connections (like ad blockers), try disabling them temporarily. Also I would check your firewall to allow for WebSockets.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.