Home / Knowledge Base / VPS and Servers / Installing n8n with HTTPS via Docker Compose and Traefik

Installing n8n with HTTPS via Docker Compose and Traefik

In this article, we'll show you how to deploy n8n with HTTPS support on your Ubuntu server using Docker Compose and the Traefik reverse proxy. This is the recommended setup for production environments.

Step 1: Connect to the server

Connect to the server via SSH. For detailed instructions, see How to Connect to a Server via SSH .

Step 2: Install Docker and Docker Compose

Follow our instructions: How to install Docker and Docker Compose .

Step 3: Prepare your domain

To connect via HTTPS, you need a domain, such as n8n.example.kz , which should point to the server's IP address.

Create the following A record at your registrar or in your DNS hosting panel:

NameTypeMeaning
n8nAYour server's IP

If you use DNS hosting from Unihost.kz , make sure the domain name servers are set to ns1.unihost.kz and ns2.unihost.kz . Instructions for changing the name server: How to change a domain's name servers .
Instructions for setting up an A record: How to set up an A record for a domain .

Step 4: Create a project folder

mkdir /opt/n8n cd /opt/n8n

Step 5: Create a .env file

Create a .env in your project folder with the following information:

DOMAIN_NAME=example.kz SUBDOMAIN=n8n GENERIC_TIMEZONE=Asia/Almaty SSL_EMAIL=you@example.kz

Once configured, n8n will be accessible at https://n8n.example.kz .

Step 6: Create folders for data

mkdir local-files

Step 7: Create docker-compose.yml

Create a docker-compose.yml in the same directory and paste the following code:

services: traefik: image: "traefik" restart: always command: - "--api.insecure=true" - "--providers.docker=true" - "--providers.docker.exposedbydefault=false" - "--entrypoints.web.address=:80" - "--entrypoints.web.http.redirections.entryPoint.to=websecure" - "--entrypoints.web.http.redirections.entrypoint.scheme=https" - "--entrypoints.websecure.address=:443" - "--certificatesresolvers.mytlschallenge.acme.tlschallenge=true" - "--certificatesresolvers.mytlschallenge.acme.email=${SSL_EMAIL}" - "--certificatesresolvers.mytlschallenge.acme.storage=/letsencrypt/acme.json" ports: - "80:80" - "443:443" volumes: - traefik_data:/letsencrypt - / var /run/docker.sock:/ var /run/docker.sock:ro n8n: image: docker.n8n.io/n8nio/n8n restart: always ports: - "127.0.0.1:5678:5678" labels: - traefik.enable= true - traefik.http.routers.n8n.rule=Host(`${SUBDOMAIN}.${DOMAIN_NAME}`) - traefik.http.routers.n8n.tls= true - traefik.http.routers.n8n.entrypoints=web,websecure - traefik.http.routers.n8n.tls.certresolver=mytlschallenge - traefik.http.middlewares.n8n.headers.SSLRedirect= true - traefik.http.middlewares.n8n.headers.STSSeconds= 315360000 - traefik.http.middlewares.n8n.headers.browserXSSFilter= true - traefik.http.middlewares.n8n.headers.contentTypeNosniff= true - traefik.http.middlewares.n8n.headers.forceSTSHeader= true - traefik.http.middlewares.n8n.headers.SSLHost=${DOMAIN_NAME} - traefik.http.middlewares.n8n.headers.STSIncludeSubdomains= true - traefik.http.middlewares.n8n.headers.STSPreload= true - traefik.http.routers.n8n.middlewares=n8n@docker environment: - N8N_HOST=${SUBDOMAIN}.${DOMAIN_NAME} - N8N_PORT= 5678 - N8N_PROTOCOL=https - NODE_ENV=production - WEBHOOK_URL=https: //${SUBDOMAIN}.${DOMAIN_NAME}/ - GENERIC_TIMEZONE=${GENERIC_TIMEZONE} volumes: - n8n_data:/home/node/.n8n - ./local-files:/files volumes: n8n_data: traefik_data: Code language:  PHP  ( php )

Step 8. Launch n8n

docker compose up -d

n8n will be automatically accessible at https://n8n.example.kz (insert your domain).

Note

If you purchase a cloud server from Unihost.kz, our technical support can install n8n with HTTPS upon your request.