Setup Instructions
This section explains how to structure the project, which files and folders are required, and what configuration options you can adjust before running the stack.
Project Structure
A typical setup looks like this:
├── docker-compose.yml # Main stack definition
├── .env # Environment variables (secrets, hostnames, tokens)
├── nginx.conf # nginx configuration
├── templates/ # Folder for PHP templates & assets
│ ├── invoice/
│ │ └── index.php
│ ├── quotation/
│ │ └── index.php
│ └── style.css
└── n8n/ # Persistent n8n workflow data
File-by-File Explanation
1. .env
- Stores environment variables.
- Keeps sensitive data (like Cloudflare tokens) out of
docker-compose.yml
. - Common variables:
TOKEN
→ Cloudflare tunnel token.N8N_HOST
→ Public hostname for n8n (e.g.,pdflab.example.com
).TZ
→ Timezone (e.g.,Asia/Dhaka
).
2. docker-compose.yml
- Defines all services in the stack:
- tunnel → Cloudflare secure tunnel.
- gotenberg → PDF rendering service.
- n8n → Workflow automation.
- php-fpm → Runs PHP templates.
- nginx → Serves templates and proxies requests.
- Handles networking, volumes, and restart policies.
- You can tweak:
- Service versions → e.g., update PHP or n8n image.
- Volumes → map new folders for logs, configs, or templates.
- Networks → add isolation or connect to other stacks.
3. nginx.conf
- Defines how nginx routes requests to PHP-FPM.
- Configures document root (usually
/var/www/html
). - Can be customized for:
- Caching → to improve performance.
- SSL termination (if not using Cloudflare tunnel directly).
- Access restrictions → IP whitelisting, basic auth, etc.
4. templates/
- Contains all PHP templates and assets.
documents/
→ Dynamic templates (e.g., invoice, quote, certificate).assets/
→ CSS, JS, and images (logos, letterhead).- Templates use PHP variables to generate HTML (filled by n8n workflows).
- You can tweak:
- Add new templates for different document types.
- Customize CSS for branding.
- Add headers/footers for corporate style.
5. data/n8n/
- Stores n8n workflows and execution history.
- Persistent volume → ensures data survives container restarts.
- You can tweak:
- Backup this folder for disaster recovery.
- Mount it to external storage if workflows need to scale.
Configuration Options
- Timezones → Set
TZ
in.env
to match your region. - Public Hostnames → Define
N8N_HOST
for webhook URLs. - Scaling → Adjust
replicas
(if using Swarm/K8s) or run multiple Gotenberg containers. - Security →
- Use
.env
for sensitive values. - Protect nginx routes if needed (auth, IP filtering).
- Rotate Cloudflare Tunnel tokens periodically.
- Use
Running the Stack
Once your files are ready:
bash
docker-compose up -d
Check that each service is running:
- n8n UI:
http://localhost:5678
- nginx/PHP templates:
http://localhost
- Gotenberg: Available internally at
http://gotenberg:3000
- Cloudflare Tunnel: Accessible via your assigned hostname