Skip to content

Deployment Overview of ComfyUI on Server

Prerequisites and Basic Requirements

The following requirements must be met on the server before deploying the application:

  • Operating System: Linux (Ubuntu/Debian based recommended for Docker and Python3 compatibility).

  • Privileges: Root access or sudo privileges are required to manage Docker, firewall, and system services.

  • Domain: The server must be accessible via the hostkey.in domain.

  • Ports:

  • Port 443 (HTTPS) is used for external access via the Nginx proxy.

  • Port 8188 is the internal port used by the ComfyUI application.

Final Panel Access URL

The application is accessible via the Fully Qualified Domain Name (FQDN) using the format <prefix>-<Server ID>.hostkey.in. Based on the configuration provided:

  • Domain Zone: hostkey.in

  • Prefix: comfyui

  • External Port: 443 (Default HTTPS, usually omitted in browser URLs)

  • URL Format: comfyui-<Server ID>.hostkey.in

Replace <Server ID> with the actual unique identifier assigned to the server instance.

File and Directory Structure

The deployment utilizes the following directory structure for configuration, data, and certificates:

  • /root/ComfyUI/: Contains the main ComfyUI application source code.

  • /root/nginx/: Contains the Docker Compose configuration and Nginx related scripts.

  • /data/nginx/: Persistent storage for Nginx user configurations and environment variables.

  • /data/nginx/nginx-certbot.env: Environment file for Certbot/Nginx configuration.

  • /data/nginx/user_conf.d/: Directory for custom Nginx server configurations.

  • /etc/letsencrypt/: Mounted volume for SSL/TLS certificates managed by Certbot (via nginx_secrets volume).

Application Installation Process

The ComfyUI application is deployed as a native system service running in the background, rather than as a Docker container. The installation involves placing the source code and creating a systemd service unit.

  • Execution Command: The application is started using Python 3 with the entry point main.py.

    /usr/bin/python3 /root/ComfyUI/main.py
    

  • Service Manager: The application is managed by systemd using a unit file generated for the service.

  • Version Control: The application runs the version of ComfyUI present in the /root/ComfyUI/ directory.

Docker Containers and Their Deployment

A reverse proxy with SSL termination is deployed using Docker. This container handles the HTTPS traffic and forwards requests to the internal ComfyUI instance.

  • Deployment Method: Docker Compose.

  • Compose File Location: /root/nginx/compose.yml

  • Container Image: jonasal/nginx-certbot:latest

  • Restart Policy: unless-stopped

To start or restart the proxy services, the following command is used:

cd /root/nginx
docker compose up -d

Docker Service Configuration

The Docker Compose configuration includes the following parameters:

Parameter Value Description
Image jonasal/nginx-certbot:latest Nginx with built-in Certbot for SSL.
Network Mode host Uses the host's network stack directly.
Volume (SSL) nginx_secrets External volume mounted at /etc/letsencrypt for certificates.
Volume (Config) /data/nginx/user_conf.d Host directory mounted to /etc/nginx/user_conf.d for configs.
Environment CERTBOT_EMAIL Set to [email protected] for certificate notifications.
Env File /data/nginx/nginx-certbot.env Path to the environment variable file.

Proxy Servers

The deployment utilizes Nginx as a reverse proxy with automatic SSL certificate management via Let's Encrypt (Certbot).

  • Proxy Image: jonasal/nginx-certbot:latest

  • SSL Provider: Let's Encrypt (Certbot)

  • Certificate Storage: Stored in the nginx_secrets volume at /etc/letsencrypt.

  • Configuration: Custom Nginx configurations are placed in /data/nginx/user_conf.d.

  • Routing:

  • External Port: 443 (HTTPS)

  • External Path: / (Root path)

  • Internal Target: localhost:8188 (ComfyUI internal port)

  • Internal Path: Empty (Root mapping)

Permission Settings

The following permission settings are applied to the relevant directories and files:

  • /root/nginx/:

  • Owner: root

  • Group: root

  • Mode: 0644 (Directory creation mode)

  • /root/ComfyUI/main.py:

  • Executable by the system user running the service (typically root or a specific service user defined in systemd).

  • /data/nginx/:

  • Must be accessible by the Docker container to mount and read configuration files.

Location of Configuration Files and Data

Component File Path Description
ComfyUI Source /root/ComfyUI/ Main application code.
Service Unit /etc/systemd/system/comfyui.service (Generated from comfyui.service.j2)
Docker Compose /root/nginx/compose.yml Configuration for the Nginx proxy.
Nginx Env /data/nginx/nginx-certbot.env Environment variables for the proxy.
Nginx Custom Config /data/nginx/user_conf.d/ Directory for custom server blocks.
SSL Certificates nginx_secrets (Docker Volume) Let's Encrypt certificates.

Available Ports for Connection

  • Port 443: HTTPS. The primary entry point for users accessing the ComfyUI web interface via the FQDN.

  • Port 8188: HTTP. The internal port used by the ComfyUI application. This port is typically not exposed directly to the public internet but is accessible via the Nginx proxy.

Starting, Stopping, and Updating

Managing the ComfyUI Application

The ComfyUI application is managed as a systemd service.

  • Start the service:

    systemctl start comfyui
    

  • Stop the service:

    systemctl stop comfyui
    

  • Restart the service:

    systemctl restart comfyui
    

  • Enable on boot:

    systemctl enable comfyui
    

Managing the Nginx Proxy

The Nginx proxy is managed via Docker Compose.

  • Start/Restart the proxy:

    cd /root/nginx
    docker compose up -d
    

  • Stop the proxy:

    cd /root/nginx
    docker compose down
    

Updating the Application

To update the ComfyUI application:

  1. Update the code in the /root/ComfyUI/ directory.

  2. Restart the systemd service:

    systemctl restart comfyui
    

To update the Nginx proxy:

  1. Pull the latest image and recreate the container:
    cd /root/nginx
    docker compose pull
    docker compose up -d
    
question_mark
Is there anything I can help you with?
question_mark
AI Assistant ×