Bad Gateway after updating n8n on Hostinger VPS Help

Hi everyone,

After updating n8n to the latest version on my Hostinger VPS (Docker + Nginx), I started getting 502 Bad Gateway when accessing the UI.

Before the update everything worked fine. Restarting the container sometimes fixes it temporarily, but the error comes back.

Has anyone experienced this after updating n8n?

Any idea what might cause it or how to fix it?

Thanks!

1 Like

Hi @jelica

502 error usually means Nginx is running fine, but it lost the connection to your n8n container. When this happens right after an update, it’s almost always one of two things: a stalled Docker container or missing WebSocket headers.

Test these options:

1. Pin a specific stable version
If your docker-compose.yml is just pulling the latest tag, it might have grabbed an unstable build or it’s hanging on a major database migration (like moving to v2). Open your compose file and explicitly pin a known stable version instead:
image: docker.n8n.io/n8nio/n8n:2.0.0 (or 1.97.0 if you want to stay on v1).

2. Fix your Nginx WebSockets
n8n relies heavily on WebSockets, and missing proxy headers will instantly throw a 502 or drop the connection. Make sure your Nginx location / block includes these exact lines:

proxy_pass http://localhost:5678;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";

3. Do a hard restart
Once your compose file is updated and Nginx is saved, completely rebuild the container so it boots cleanly:
docker compose down && docker compose up -d


Hope this will help you!

If none of the above solutions work, run the following command to check the logs for your n8n container:

docker logs <your-n8n-container-name> --tail 100

This will show you the last 100 lines of the log, which should include details about what happened just before the crash. Please share the log output with me so I can help you diagnose the issue.

Hi @jelica Welcome!
First what i would recommend is roll back to the most stable versions by far which are 2.0.0 and then try that, also make sure your tunneling is working.

Welcome to the n8n community @jelica

The 502 Bad Gateway error that occurs after the update of n8n is usually due to compatibility issues between the new n8n version and your existing setup, or resource limitations on your VPS.

Solutions to Try:

1. Check n8n Container Logs (Most Important)

First, see what’s actually failing:

docker logs n8n --tail 100 -f

Look for errors like:

  • “Task runner connection failed”

  • “Out of memory”

  • “Database migration error”

  • Port binding errors

2. Increase Memory Limits

Newer n8n versions need more resources. Update your docker-compose.yml:

services:
  n8n:
    image: n8nio/n8n:latest
    restart: unless-stopped
    ports:
      - "5678:5678"
    deploy:
      resources:
        limits:
          memory: 2G  # Increase from default
        reservations:
          memory: 1G
    environment:
      - NODE_OPTIONS=--max-old-space-size=2048
    # ... rest of config

3. Fix Task Runner Issues (n8n 2.x)

If you updated to n8n 2.x, you may need to configure runners:

Option A: Use Internal Runners (Simpler)

services:
  n8n:
    image: n8nio/n8n:latest
    environment:
      - N8N_RUNNERS_MODE=internal  # Add this
    # ... rest of config

Option B: Add External Runners (if needed)

services:
  n8n:
    image: n8nio/n8n:latest
    environment:
      - N8N_RUNNERS_MODE=external
      - N8N_RUNNERS_TASK_BROKER_URI=n8n-task-runner-js:5679
    depends_on:
      - n8n-task-runner-js

  n8n-task-runner-js:
    image: n8nio/n8n-task-runner-js:latest
    restart: unless-stopped
    environment:
      - N8N_RUNNERS_TASK_BROKER_URI=ws://n8n:5679

4. Update Nginx Configuration

Newer n8n versions may need updated Nginx settings for WebSockets:

server {
    listen 80;
    server_name your-domain.com;

    location / {
        proxy_pass http://localhost:5678;
        proxy_http_version 1.1;
        
        # WebSocket support (critical for n8n)
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        
        # Standard proxy headers
        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;
        
        # Timeouts
        proxy_connect_timeout 300s;
        proxy_send_timeout 300s;
        proxy_read_timeout 300s;
        
        # Buffer settings
        proxy_buffering off;
    }
}

After updating Nginx config:

sudo nginx -t  # Test configuration
sudo systemctl reload nginx

5. Check Port Conflicts

Verify n8n is actually running and listening:

docker ps  # Check if container is running
docker exec n8n netstat -tuln | grep 5678  # Check if port is bound
curl http://localhost:5678  # Test direct access

6. Rollback to Previous Version (If Needed)

If the issue persists, temporarily rollback:

services:
  n8n:
    image: n8nio/n8n:2.9.3  # Use specific working version
    # ... rest of config

Then:

docker-compose down
docker-compose pull
docker-compose up -d

7. Check VPS Resources

Hostinger VPS might be running out of resources:

# Check memory usage
free -h

# Check disk space
df -h

# Check CPU usage
top

# Check Docker stats
docker stats n8n

If memory is low, consider:

  • Upgrading your VPS plan

  • Reducing other services

  • Adding swap space

8. Database Migration Issues

If you’re using PostgreSQL/MySQL, check for migration errors:

docker logs n8n | grep -i "migration\|database"

If migrations failed, you may need to:

  • Backup your database

  • Manually run migrations

  • Or restore from backup and retry update

The most common cause after updates is either the task runner configuration or insufficient memory on the VPS.

2 Likes

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