n8n behind Nginx with SSL, webhooks and WebSockets

The reverse proxy is where most n8n self-hosting problems live: a laggy editor, webhook URLs that point at localhost, or "too many redirects" after HTTPS. Here is the Nginx config that gets all three right, plus the reasoning so you can debug your own.

Disclosure: contains an affiliate link to Inferno VPS.

What the proxy has to do

n8n listens on plain HTTP on port 5678. Nginx sits in front and handles three jobs: terminate TLS (so browsers see HTTPS), upgrade WebSocket connections (so the editor is responsive), and pass the correct headers so n8n knows its real public URL. Get any one wrong and the symptom is confusing. This guide assumes you already have n8n running from the Docker Compose setup with the port bound to 127.0.0.1:5678.

Prerequisites

Step 1 — Base Nginx site

sudo apt install -y nginx certbot python3-certbot-nginx
sudo nano /etc/nginx/sites-available/n8n
server {
    listen 80;
    server_name n8n.example.com;

    client_max_body_size 32m;   # room for binary data / file uploads

    location / {
        proxy_pass http://127.0.0.1:5678;
        proxy_http_version 1.1;

        # WebSocket upgrade — required for a responsive editor
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        # Real client info so n8n builds correct URLs
        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;

        proxy_read_timeout 3600s;   # long-running workflow executions
        proxy_send_timeout 3600s;
    }
}

Step 2 — Enable and get a certificate

sudo ln -s /etc/nginx/sites-available/n8n /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
sudo certbot --nginx -d n8n.example.com --redirect

certbot adds the 443 server block, the certificate paths and an HTTP→HTTPS redirect, and installs a renewal timer. Confirm renewal works:

sudo certbot renew --dry-run

Step 3 — Tell n8n it is behind a proxy

Nginx is now terminating TLS, but n8n still needs to know its public address, or webhook URLs come out wrong. In your Compose environment (from the env reference):

- N8N_HOST=n8n.example.com
- N8N_PROTOCOL=https
- WEBHOOK_URL=https://n8n.example.com/
- N8N_PROXY_HOPS=1

N8N_PROXY_HOPS=1 tells n8n to trust exactly one proxy (Nginx) when reading X-Forwarded-For. Without it, recent n8n versions log a warning and can misread the client IP. Recreate the container after changing env:

docker compose up -d

The three classic failures

Editor is slow, drag-and-drop lags, executions do not update live

WebSockets are not being upgraded. Confirm the Upgrade and Connection "upgrade" headers are present and that proxy_http_version 1.1; is set. Reload Nginx and hard-refresh the browser.

Webhook URL shows http://localhost:5678

WEBHOOK_URL and N8N_HOST are unset or did not apply. Set both and recreate the container. A restart alone does not reload environment variables.

"Too many redirects" (ERR_TOO_MANY_REDIRECTS)

n8n is set to N8N_PROTOCOL=https but Nginx is forwarding as HTTP without X-Forwarded-Proto. Add proxy_set_header X-Forwarded-Proto $scheme; — n8n then knows the original request was HTTPS and stops redirecting.

Optional — a security header block

add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;

Add inside the 443 server block. Do not add a restrictive Content-Security-Policy blindly — n8n's editor loads inline assets and an over-tight CSP breaks it.

Low latency to your webhooks matters

If external services call your webhooks, a data center near them cuts round-trip time. Inferno runs eight EU + Asia locations with DDoS protection, from $3.49/mo.

View Inferno plans →

What to do next


Author: Riku Lehtinen — Linux sysadmin, Tampere. Last tested: 2026-05-19 on Nginx 1.24, n8n 1.62, certbot 2.x, Ubuntu 22.04.