Using n8n with NGINX Reverse Proxy

Piotr Pliszko

Recently I've deployed a self-hosted n8n instance on one of my virtual machines. In front of all apps on this server, I have NGINX Reverse Proxy. Unfortunately, when I've tried to configure a webhook I've noticed weird behavior - problems with communication with the n8n frontend, not being able to stop listening for testing webhook calls, etc.

One of the most notable issues was a WebSocket error:

WebSocket connection to 'wss://n8n.example.com/rest/push?sessionId=abcdef' failed

After some research, I've found a few issues with my NGINX configuration that caused this behavior. Below there is a fragment of configuration that works perfectly.

# nginx.conf

# ...
http {
    # ...

    map $http_upgrade $connection_upgrade {
        default upgrade;
        ""      close;
    }

    # ...
}
# ...
# sites-available/n8n.example.com

server {
    server_name n8n.example.com www.n8n.example.com; # your domain

    location / {
        proxy_pass http://localhost:5678; # your n8n address

        chunked_transfer_encoding off;
        proxy_http_version                 1.1;
        proxy_cache_bypass                 $http_upgrade;
        proxy_ssl_server_name              on;

        proxy_set_header Host $host;
        proxy_set_header Connection '';
        proxy_set_header Upgrade           $http_upgrade;
        proxy_set_header Connection        $connection_upgrade;
        proxy_set_header X-Real-IP         $remote_addr;
        proxy_set_header Forwarded         $proxy_add_forwarded;

        # ...
    }
    # ...
}

If you have similar issues with your n8n instance hidden behind the NGINX reverse proxy check your config - maybe you miss some of these settings.

If you want to read more about WebSocket support in NGINX, check the official documentation.

If you have any questions or feedback, feel free to reach out to me on GitHub, Twitter/X or LinkedIn!