Back to tutorials
Tutorial

ComfyUI Reverse Proxy Setup With Nginx And SSL

Tutorial: secure ComfyUI behind Nginx with HTTPS, basic auth, upload limits, and safer binding for team access.

By Anurag Singh
Updated on Nov 19, 2026
Category: Tutorial
Share article
ComfyUI Reverse Proxy Setup With Nginx And SSL

ComfyUI runs best when it stays on localhost. Let a hardened web server handle anything public-facing.

That’s the goal here: secure ComfyUI behind Nginx with HTTPS, basic auth, sensible upload limits, and safer network binding.

This walkthrough is for GPU server operators who want to share ComfyUI with a small team on real infrastructure (a GPU VPS or dedicated server).

By the end, you’ll have a clean URL like https://comfyui.example.com, a login prompt, and an edge you can monitor and tighten over time.

What you’ll build (and what you won’t)

  • Nginx reverse proxy in front of ComfyUI
  • HTTPS using Let’s Encrypt (Certbot)
  • Basic authentication for quick team-only access
  • Upload limits to avoid accidental multi-GB posts filling your disk
  • Safer binding: ComfyUI listens only on 127.0.0.1

This does not give you per-user accounts, audit trails, or SSO. Basic auth is intentionally simple.

If you need stronger identity controls, put ComfyUI behind your identity provider (or a zero-trust gateway).

For a small team, this baseline removes the obvious foot-guns.

Prerequisites and sizing (GPU, VRAM, RAM, disk)

Nginx won’t change ComfyUI’s compute needs. Sizing still depends on the models, resolutions, and workflows you run.

Most deployments fail on the boring parts. Plan for RAM headroom, disk growth, and upload limits.

  • OS: Ubuntu 24.04 LTS or Ubuntu 22.04 LTS (works similarly on Debian 12)
  • GPU: Any CUDA-capable NVIDIA GPU for most common workflows
  • VRAM: 8 GB for lighter SD/SDXL workflows; 12–24 GB gives you more room for higher resolutions and larger pipelines
  • System RAM: 16 GB minimum; 32 GB is smoother if multiple users queue jobs
  • Disk: 50–150 GB free is typical once you add checkpoints, LoRAs, and caches
  • Domain: comfyui.example.com pointed to your server

If you’re still picking hardware, a GPU HostMyCode dedicated server is the comfortable option for sustained image generation.

If you want a smaller footprint with a fixed monthly bill, start on a HostMyCode VPS.

Scale up once your workflows stop changing every week.

Step 1: Point DNS to your GPU server

Create an A record for your subdomain:

  • comfyui.example.com → your server IPv4

Verify it from your laptop:

dig +short comfyui.example.com

If you manage DNS where you host, using HostMyCode Domains keeps billing and DNS updates in one place.

Step 2: Install Nginx and allow only what you need

On Ubuntu, install Nginx plus the small utilities you’ll use for auth and firewalling:

sudo apt update
sudo apt install -y nginx apache2-utils ufw

Now restrict inbound traffic. For this setup you need SSH, HTTP (for certificate issuance), and HTTPS:

sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw enable
sudo ufw status

If you already run other web services, confirm nothing else is bound to ports 80/443 before you continue.

Step 3: Run ComfyUI on localhost only (safer network binding)

The most common mistake is exposing ComfyUI on 0.0.0.0 “temporarily,” then forgetting about it. Don’t do that.

Keep ComfyUI private. Publish only Nginx.

Your startup method may differ (git checkout + venv, Docker, etc.). The requirement stays the same: listen on 127.0.0.1.

If you start ComfyUI directly (typical Python run), use:

cd /opt/ComfyUI
python3 main.py --listen 127.0.0.1 --port 8188

If your build doesn’t support --listen, use the equivalent supported option.

You can also bind through your process runner.

For Docker, publish only to 127.0.0.1, for example -p 127.0.0.1:8188:8188.

Sanity check from the server itself:

curl -I http://127.0.0.1:8188/

You should see an HTTP response.

From your laptop, you should not be able to reach port 8188 directly.

If you need a reference ComfyUI base deployment first, follow HostMyCode’s ComfyUI guide and come back to this reverse proxy hardening: Deploy ComfyUI on a GPU Server With Nginx.

Step 4: Create a basic auth file for your team

Basic auth isn’t fancy, but it’s reliable. Use strong passwords.

Rotate passwords when someone leaves the project.

Create a password file and add a user:

sudo htpasswd -c /etc/nginx/.htpasswd comfyuser

Add more users later (without -c):

sudo htpasswd /etc/nginx/.htpasswd anotheruser

Lock down file permissions:

sudo chown root:www-data /etc/nginx/.htpasswd
sudo chmod 640 /etc/nginx/.htpasswd

Step 5: Configure Nginx reverse proxy for ComfyUI

Create a dedicated server block. On Ubuntu’s default Nginx layout, that lives in /etc/nginx/sites-available/.

sudo nano /etc/nginx/sites-available/comfyui

Paste this configuration (adjust the domain):

server {
    listen 80;
    server_name comfyui.example.com;

    # Increase if your workflows need bigger uploads.
    # Keep it bounded to reduce disk-fill incidents.
    client_max_body_size 50m;

    location / {
        auth_basic "ComfyUI";
        auth_basic_user_file /etc/nginx/.htpasswd;

        proxy_pass http://127.0.0.1:8188;
        proxy_http_version 1.1;

        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;

        # WebSocket support (ComfyUI UI updates often rely on it)
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        # Avoid long generations getting cut off
        proxy_read_timeout 3600;
        proxy_send_timeout 3600;
    }
}

Enable the site and reload Nginx:

sudo ln -s /etc/nginx/sites-available/comfyui /etc/nginx/sites-enabled/comfyui
sudo nginx -t
sudo systemctl reload nginx

Test from your laptop. Open http://comfyui.example.com.

You should see a login prompt first, then the UI.

Step 6: Add HTTPS with Let’s Encrypt (Certbot)

Install Certbot for Nginx, then request a certificate for your domain:

sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d comfyui.example.com

Pick the option that redirects HTTP to HTTPS.

After Certbot finishes, validate the config and reload:

sudo nginx -t
sudo systemctl reload nginx

Confirm renewals are scheduled:

sudo systemctl status certbot.timer
sudo certbot renew --dry-run

If you prefer DNS-based validation (useful when you can’t open port 80), HostMyCode has a separate guide for wildcard certs: Add Let’s Encrypt Wildcard SSL with DNS validation.

Step 7: Tighten Nginx defaults (headers and sane TLS)

Certbot wires up the certificate. You still need a few guardrails.

These headers reduce framing issues and content-type sniffing problems.

Edit the HTTPS server block Certbot created (same file).

Add these inside your server { ... } block that listens on 443:

add_header X-Frame-Options "DENY" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "no-referrer" always;

# If ComfyUI is only for your team, consider a strict policy.
# You may need to relax this if you embed external assets.
add_header Content-Security-Policy "default-src 'self'; connect-src 'self' wss: https:; img-src 'self' data: blob:; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline'" always;

Reload after validating syntax:

sudo nginx -t
sudo systemctl reload nginx

If the UI breaks, comment out the CSP line first.

CSP failures are common because ComfyUI setups and browser behavior vary.

Step 8: Set upload limits that match your workflows (and your disk)

Uploads can fill disks quickly. Inputs, temporary files, and outputs add up.

Your first guardrail is client_max_body_size.

Common starting values:

  • 25m: enough for typical PNG/JPEG inputs
  • 50m: safer if you pass higher-res images
  • 100m+: only if your workflows require it (and you trust users)

Watch the filesystem too. Once people start experimenting, daily disk growth is normal.

Keep this diagnostic handy: Disk Full on VPS: find large files and free space safely.

Step 9: Make it a service (systemd) so it survives reboots

If you already manage ComfyUI with systemd or Docker, don’t reinvent it.

You just need a predictable process that comes back after reboots and crashes.

If you’re not using a process manager yet, systemd is the simplest option on Ubuntu.

Create a dedicated user:

sudo adduser --system --group --home /opt/comfyui comfyui

Assuming your ComfyUI directory is /opt/ComfyUI and you run it with a venv, create:

sudo nano /etc/systemd/system/comfyui.service

Example unit (adjust paths and python environment):

[Unit]
Description=ComfyUI
After=network.target

[Service]
Type=simple
User=comfyui
Group=comfyui
WorkingDirectory=/opt/ComfyUI

# If you use a venv, point ExecStart to its python.
ExecStart=/usr/bin/python3 /opt/ComfyUI/main.py --listen 127.0.0.1 --port 8188

Restart=on-failure
RestartSec=3

# Basic hardening (won't break most installs)
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=full
ProtectHome=true

[Install]
WantedBy=multi-user.target

Enable and start it:

sudo systemctl daemon-reload
sudo systemctl enable --now comfyui
sudo systemctl status comfyui --no-pager

Watch logs while you load the UI:

sudo journalctl -u comfyui -f

Step 10: Put the endpoint on a shorter leash (optional, but recommended)

Nginx + basic auth is your front door. You can still reduce exposure with two upgrades.

First, limit who can reach the door. Second, slow down abusive clients.

Option A: IP allowlist (best for a fixed office/VPN)

Add this inside the location / block, above proxy_pass:

allow 203.0.113.10;
allow 198.51.100.0/24;
deny all;

This is blunt, and it works.

If people travel, route them through a VPN or tunnel so their source IP stays consistent.

Option B: Hide ComfyUI behind a private tunnel

If you don’t want ComfyUI on the public internet at all, put it behind a tunnel and keep firewall ports closed.

This pattern works well for admin tools and internal apps.

HostMyCode’s Cloudflare Tunnel tutorial is a solid starting point: Set up Cloudflare Tunnel for private admin endpoints.

Option C: Basic abuse protection

If you see repeated auth prompts or noisy traffic, add Fail2ban for Nginx.

The setup is the same whether you protect WordPress or ComfyUI.

In both cases, you react to Nginx auth/access logs.

Use this as the base pattern: Set up Fail2ban for Nginx on Ubuntu VPS.

Quick verification checklist (5 minutes)

  • ComfyUI binds to localhost: ss -lntp | grep 8188 shows 127.0.0.1:8188
  • Nginx binds to public: ss -lntp | grep -E '(:80|:443)'
  • HTTP redirects to HTTPS
  • Basic auth required (incognito window test)
  • Uploads limited (try a file slightly larger than your limit)
  • Cert auto-renewal enabled: systemctl status certbot.timer

Common problems and fixes

502 Bad Gateway from Nginx

  • ComfyUI isn’t running. Check: systemctl status comfyui
  • Wrong port in proxy_pass. Confirm ComfyUI is on 8188: curl -I http://127.0.0.1:8188/
  • ComfyUI bound to a different IP or only IPv6. Fix by binding explicitly to 127.0.0.1.

Web UI loads but jobs don’t update / UI feels stuck

This is usually WebSocket proxying.

Confirm these lines are present:

proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";

413 Request Entity Too Large

That’s your upload limit doing its job.

Raise client_max_body_size in the server block, reload Nginx, and keep the limit as low as your workflows allow.

Disk usage keeps climbing

Generated images, model downloads, and caches add up fast.

For a safe cleanup workflow, use: find large files and free space safely.

Operational notes (what to document for your team)

  • One URL to access ComfyUI (your HTTPS domain)
  • How to request access (who creates basic auth users)
  • Where outputs are stored on disk (so you can back them up or prune)
  • Maintenance window for model updates and reboots

If ComfyUI is becoming a dependency for client work or internal production, treat it like one.

Take snapshots, back up custom workflows, and make sure you can restore onto a fresh server without guesswork.

If you want ComfyUI reachable by your team without exposing the raw app port, run it on a VPS or GPU server where you control the firewall and TLS edge. Start with a HostMyCode VPS, or move straight to managed VPS hosting if you’d rather spend time on workflows than server upkeep.

FAQ

Do I need a dedicated server to secure ComfyUI behind Nginx?

No. The Nginx + HTTPS + basic auth pattern works on a VPS or a dedicated box.

Dedicated servers make sense when your GPU workload is heavy and continuous.

Is basic auth “secure enough” for team access?

For a small, trusted team, basic auth over HTTPS is a practical baseline.

If you need user-level auditing, MFA, or automated offboarding, front it with an identity-aware proxy or a private tunnel.

Should ComfyUI bind to 0.0.0.0 if I’m using Nginx?

No. Bind ComfyUI to 127.0.0.1 and expose only Nginx on ports 80/443.

It reduces your attack surface and avoids accidental public exposure.

What upload limit should I set in Nginx?

Start at 50m. If your workflows import large source images, move to 100m.

Avoid unlimited uploads unless you also enforce disk quotas and monitoring.

How do I share ComfyUI privately without opening ports 80/443?

Use a tunnel (or VPN) so only authenticated users can reach the endpoint.

A common approach is Cloudflare Tunnel with an access policy.

Summary

You now have ComfyUI running on localhost, with Nginx handling HTTPS, authentication, timeouts, and upload limits.

It’s a clean way to share a GPU image generation box with a small team without exposing a raw application port.

If you’re deploying this for client work or internal production, use infrastructure you can resize as usage grows—typically a HostMyCode dedicated server or a well-sized HostMyCode VPS.