7.1 KiB
Coolify Deployment Guide
This guide covers deploying ai.allucanget.biz using Coolify with Nixpacks from the repository https://git.allucanget.biz/allucanget/ai.allucanget.biz.git.
Architecture Overview
The application consists of two Python services:
| Service | Framework | Port | Description |
|---|---|---|---|
| Backend | FastAPI + uvicorn | 12015 | REST API, auth, AI generation, DuckDB |
| Frontend | Flask + gunicorn | 12016 | SSR web UI, session auth, proxy to backend |
Coolify's built-in reverse proxy routes traffic:
/api/*→ Backend (port 12015)/→ Frontend (port 12016)
Prerequisites
- A Coolify instance (self-hosted or Cloud)
- Git repository pushed to
https://git.allucanget.biz/allucanget/ai.allucanget.biz.git - Domain configured to point to your Coolify server
Step 1: Create Backend Service
-
In Coolify, click Add Resource → Deploy a new resource → Git
-
Connect your Git repository (
git.allucanget.biz) -
Select the
ai.allucanget.bizrepository -
Choose the
mainbranch -
Set Build Pack to
nixpacks -
Set Base Directory to
/backend- this tells Nixpacks to look in thebackend/subdirectory forrequirements.txtand the Python application -
Set Ports Exposed to
12015 -
Set Start Command to:
uvicorn app.main:app --host 0.0.0.0 --port 12015 -
Click Create Resource
Important: Nixpacks copies the contents of the Base Directory to
/app/in the container. When Base Directory is/backend, thebackend/folder wrapper is removed — onlyapp/,tests/, andrequirements.txtare copied. Therefore the start command usesapp.main:app(notbackend.app.main:app).
Backend Environment Variables
Add these as Runtime environment variables in Coolify:
| Variable | Description | Example |
|---|---|---|
OPENROUTER_API_KEY |
OpenRouter API key for AI generation | sk-or-v1-... |
JWT_SECRET |
Secret key for JWT token signing | Generate with openssl rand -hex 32 |
APP_URL |
Public URL of the backend | https://api.ai.allucanget.biz |
APP_NAME |
Application name | All You Can GET AI |
CORS_ORIGINS |
Comma-separated allowed origins | https://ai.allucanget.biz |
Step 2: Create Frontend Service
-
In Coolify, click Add Resource → Deploy a new resource → Git
-
Select the same repository
-
Choose the
mainbranch -
Set Build Pack to
nixpacks -
Set Base Directory to
/frontend- this tells Nixpacks to look in thefrontend/subdirectory forrequirements.txtand the Python application -
Set Ports Exposed to
12016 -
Set Start Command to:
gunicorn app.main:app --bind 0.0.0.0:12016 --workers 2 --timeout 120 -
Click Create Resource
Note: Nixpacks will automatically detect and install only the production dependencies from
requirements.txt. Important: Nixpacks copies the contents of the Base Directory to/app/in the container. When Base Directory is/frontend, thefrontend/folder wrapper is removed — onlyapp/,tests/, andrequirements.txtare copied. Therefore the start command usesapp.main:app(notfrontend.app.main:app).
Frontend Environment Variables
Add these as Runtime environment variables in Coolify:
| Variable | Description | Example |
|---|---|---|
FLASK_SECRET_KEY |
Flask session cookie signing key | Generate with openssl rand -hex 32 |
BACKEND_URL |
Internal URL to reach the backend service | http://localhost:12015 (or use Coolify's internal networking) |
Step 3: Configure Reverse Proxy
Coolify provides a built-in reverse proxy. Configure routing rules:
Backend Proxy Rules
- Domain:
api.ai.allucanget.biz(or subdomain of your choice) - Port:
12015 - Path:
/api/*→ forward to backend
Frontend Proxy Rules
- Domain:
ai.allucanget.biz - Port:
12016 - Path:
/→ forward to frontend
Step 4: SSL/TLS
Enable HTTPS in Coolify for both services:
- Go to each service's settings
- Enable Auto HTTPS (Let's Encrypt)
- Configure domain names
- Coolify automatically handles certificate renewal
Step 5: Persistent Storage (Optional)
If you want to persist DuckDB data:
- In Coolify, go to the Backend service
- Navigate to Persistent Storage
- Add a volume mount:
- Host Path:
/data(or any path on the host) - Container Path:
/app/data - Type:
Bind MountorVolume
- Host Path:
Troubleshooting
Backend healthcheck stays unhealthy
- Check backend logs in Coolify
- Verify
OPENROUTER_API_KEYandJWT_SECRETare set - Verify volume mount at
/app/datais writable
Backend won't start
- Check that
OPENROUTER_API_KEYis set - Verify
JWT_SECRETis a sufficiently long random string - Check logs in Coolify's Logs tab
Frontend can't reach backend
- Ensure
BACKEND_URLpoints to the correct internal URL - If both services are on the same Coolify server, use
http://localhost:12015 - Check that the backend service is running and healthy
CORS errors
- Set
CORS_ORIGINSto include your frontend domain - Example:
https://ai.allucanget.biz
Nixpacks build fails
- Verify the base directory is correct (
/backendor/frontend) - Check that
requirements.txtexists in the base directory - Review build logs in Coolify
Environment Variable Summary
All required environment variables:
| Variable | Service | Required |
|---|---|---|
OPENROUTER_API_KEY |
Backend | Yes |
JWT_SECRET |
Backend | Yes |
APP_URL |
Backend | Yes |
APP_NAME |
Backend | No (defaults to "All You Can GET AI") |
CORS_ORIGINS |
Backend | Yes |
FLASK_SECRET_KEY |
Frontend | Yes |
BACKEND_URL |
Frontend | Yes |
Deployment Checklist
- Repository pushed to Git
- Backend service created with correct base directory (
/backend) - Backend environment variables configured
- Frontend service created with correct base directory (
/frontend) - Frontend environment variables configured
- SSL certificates enabled
- Domain names configured
- Health checks passing
- Logs reviewed for errors