Add Dokploy deployment configuration with Neon database

- Add docker-compose.yml for Dokploy deployment
- Add Dockerfile optimized for production
- Add nginx.conf for SSL and reverse proxy
- Update Django settings for ai.quantumtaskai.com domain
- Add Neon database configuration
- Add deployment guides and environment generators
- Remove CapRover specific files
This commit is contained in:
thecyberlearn 2025-09-06 10:18:24 +05:30
parent c0a22dddd5
commit 5ec22c0487
16 changed files with 1215 additions and 107 deletions

49
.env.dokploy Normal file
View File

@ -0,0 +1,49 @@
# Dokploy Environment Variables for ai.quantumtaskai.com
# Copy this file and configure the values for your Dokploy deployment
# Django Configuration
SECRET_KEY=your-super-secret-key-here-generate-50-random-characters-minimum
DEBUG=false
ALLOWED_HOSTS=ai.quantumtaskai.com,*.quantumtaskai.com,quantumtaskai.com
CSRF_TRUSTED_ORIGINS=https://ai.quantumtaskai.com,https://quantumtaskai.com,https://www.quantumtaskai.com
# Domain Configuration
DOMAIN=ai.quantumtaskai.com
SITE_URL=https://ai.quantumtaskai.com
# Neon Database (Serverless PostgreSQL)
NEON_DATABASE_URL=postgresql://your_username:your_password@your_endpoint.neon.tech/quantumtasks_ai?sslmode=require
# Email Configuration (Required for production)
EMAIL_HOST_USER=your-email@gmail.com
EMAIL_HOST_PASSWORD=your-gmail-app-password
DEFAULT_FROM_EMAIL=Quantum Tasks AI <noreply@ai.quantumtaskai.com>
REQUIRE_EMAIL_VERIFICATION=true
# Stripe Payment Configuration
STRIPE_SECRET_KEY=sk_live_your_stripe_secret_key_here
STRIPE_WEBHOOK_SECRET=whsec_your_stripe_webhook_secret_here
# AI API Keys
OPENAI_API_KEY=sk-your_openai_api_key_here
GROQ_API_KEY=gsk_your_groq_api_key_here
# Search API Configuration
SERPAPI_API_KEY=your_serpapi_key_here
# Weather API (Optional)
OPENWEATHER_API_KEY=your_openweather_api_key_here
# N8N Webhook URLs (Optional - for advanced AI agents)
N8N_WEBHOOK_DATA_ANALYZER=https://your-n8n-instance.com/webhook/data-analyzer
N8N_WEBHOOK_FIVE_WHYS=https://your-n8n-instance.com/webhook/five-whys
N8N_WEBHOOK_JOB_POSTING=https://your-n8n-instance.com/webhook/job-posting
N8N_WEBHOOK_SOCIAL_ADS=https://your-n8n-instance.com/webhook/social-ads
N8N_WEBHOOK_FAQ_GENERATOR=https://your-n8n-instance.com/webhook/faq-generator
# Security Settings
SECURE_SSL_REDIRECT=true
SECURE_PROXY_SSL_HEADER=HTTP_X_FORWARDED_PROTO,https
# Dokploy Detection (automatically set by Dokploy)
COMPOSE_PROJECT_NAME=quantumtasks-ai

30
.env.neon Normal file
View File

@ -0,0 +1,30 @@
# Generated Environment Variables for Dokploy + Neon
# Generated on: Saturday 06 September 2025 09:53:47 AM IST
# ESSENTIAL VARIABLES
SECRET_KEY=b+6h(2YAa#8NPRfHApILsw&A8m^yQU=QfPMBCCsjEx31-)sDZh
DEBUG=false
ALLOWED_HOSTS=ai.quantumtaskai.com,*.quantumtaskai.com,quantumtaskai.com
CSRF_TRUSTED_ORIGINS=https://ai.quantumtaskai.com,https://quantumtaskai.com
# NEON DATABASE VARIABLE
NEON_DATABASE_URL=postgresql://your_username:your_password@your_endpoint.neon.tech/quantumtasks_ai?sslmode=require
# Get this from Neon dashboard: Database → Connection Details
# EMAIL CONFIGURATION (Fill in your values)
EMAIL_HOST_USER=your-email@gmail.com
EMAIL_HOST_PASSWORD=your-gmail-app-password
DEFAULT_FROM_EMAIL=Quantum Tasks AI <noreply@ai.quantumtaskai.com>
REQUIRE_EMAIL_VERIFICATION=true
# SECURITY SETTINGS
SECURE_SSL_REDIRECT=true
SECURE_PROXY_SSL_HEADER=HTTP_X_FORWARDED_PROTO,https
COMPOSE_PROJECT_NAME=quantumtasks-ai
# OPTIONAL VARIABLES (Configure as needed)
# STRIPE_SECRET_KEY=sk_live_your_stripe_secret_key_here
# OPENAI_API_KEY=sk-your_openai_api_key_here
# GROQ_API_KEY=gsk_your_groq_api_key_here
# SERPAPI_API_KEY=your_serpapi_key_here
# OPENWEATHER_API_KEY=your_weather_api_key_here

214
DOKPLOY_DEPLOYMENT.md Normal file
View File

@ -0,0 +1,214 @@
# Dokploy Deployment Guide for Quantum Tasks AI
Deploy Quantum Tasks AI to **ai.quantumtaskai.com** using Dokploy with PostgreSQL database.
## 🚀 Quick Deployment Steps
### 1. Prerequisites
- Dokploy server installed and running
- Domain `ai.quantumtaskai.com` pointing to your Dokploy server
- SSL certificate for the domain (Dokploy can handle Let's Encrypt automatically)
### 2. Create New Project in Dokploy
1. Log into your Dokploy dashboard
2. Click "Create New Project"
3. Choose "Compose" deployment type
4. Name: `quantumtasks-ai`
5. Repository: Connect your Git repository
### 3. Upload Configuration Files
Make sure these files are in your repository root:
- ✅ `docker-compose.yml` (created)
- ✅ `Dockerfile` (created)
- ✅ `nginx.conf` (created)
- ✅ `.env.dokploy` (template created)
### 4. Environment Configuration
In Dokploy, set these environment variables:
#### Essential Variables (Required)
```env
# Django Core
SECRET_KEY=your-super-secret-key-here-50-chars-minimum
DEBUG=false
ALLOWED_HOSTS=ai.quantumtaskai.com,*.quantumtaskai.com
CSRF_TRUSTED_ORIGINS=https://ai.quantumtaskai.com
# Database
POSTGRES_DB=quantumtasks_ai
POSTGRES_PASSWORD=your-strong-postgres-password
DATABASE_URL=postgresql://postgres:your-password@db:5432/quantumtasks_ai
# Email (Required for user verification)
EMAIL_HOST_USER=your-email@gmail.com
EMAIL_HOST_PASSWORD=your-gmail-app-password
```
#### Optional Variables (Recommended)
```env
# Payment Processing
STRIPE_SECRET_KEY=sk_live_your_stripe_key
# AI APIs
OPENAI_API_KEY=sk-your_openai_key
GROQ_API_KEY=gsk_your_groq_key
SERPAPI_API_KEY=your_serpapi_key
# Weather API
OPENWEATHER_API_KEY=your_weather_key
```
### 5. Domain Configuration
1. In Dokploy project settings:
- **Domain**: `ai.quantumtaskai.com`
- **SSL**: Enable (Let's Encrypt)
- **Port**: 80 (nginx will handle SSL redirect)
2. DNS Setup:
```
A ai.quantumtaskai.com -> YOUR_DOKPLOY_SERVER_IP
```
### 6. Deploy
1. Click "Deploy" in Dokploy dashboard
2. Monitor the build process
3. Wait for all services to be healthy
## 🏗️ Architecture Overview
```
Internet -> Nginx (SSL/Proxy) -> Django App -> PostgreSQL
```
### Services:
- **nginx**: Reverse proxy with SSL termination, static files serving
- **web**: Django application (Gunicorn)
- **db**: PostgreSQL 15 database
### Volumes:
- `postgres_data`: Database persistence
- `static_volume`: Static files (CSS, JS, images)
- `media_volume`: User uploaded files
## 🔧 Post-Deployment Tasks
### 1. Database Initialization
```bash
# Access your Dokploy server and run:
docker exec -it quantumtasks-ai_web_1 python manage.py migrate
docker exec -it quantumtasks-ai_web_1 python manage.py createsuperuser
```
### 2. Collect Static Files (if needed)
```bash
docker exec -it quantumtasks-ai_web_1 python manage.py collectstatic --noinput
```
### 3. Test the Deployment
- Visit: https://ai.quantumtaskai.com/health/
- Expected response: `{"status": "healthy", ...}`
## 🔍 Monitoring & Troubleshooting
### Health Checks
- **Application**: https://ai.quantumtaskai.com/health/
- **Admin Panel**: https://ai.quantumtaskai.com/admin/
### Log Access
```bash
# View application logs
docker logs quantumtasks-ai_web_1 -f
# View database logs
docker logs quantumtasks-ai_db_1 -f
# View nginx logs
docker logs quantumtasks-ai_nginx_1 -f
```
### Common Issues
#### SSL Certificate Issues
- Ensure domain is correctly pointing to server
- Check Dokploy SSL configuration
- Verify Let's Encrypt rate limits
#### Database Connection Issues
- Check PostgreSQL logs
- Verify DATABASE_URL format
- Ensure database container is healthy
#### Static Files Not Loading
- Check nginx configuration
- Verify static volume mounting
- Run collectstatic if needed
## 🔐 Security Features
- **HTTPS Only**: Automatic HTTP to HTTPS redirect
- **Security Headers**: XSS, CSRF, Content-Type protection
- **Rate Limiting**: API and web request throttling
- **Database Security**: Isolated database container
- **Secrets Management**: Environment variables only
## 📊 Performance Features
- **Nginx Caching**: Static files cached for 1 year
- **Gzip Compression**: Text content compressed
- **Database Connection Pooling**: Optimized DB connections
- **Health Checks**: Automatic service monitoring
## 🔄 Updates & Maintenance
### Updating the Application
1. Push code changes to your Git repository
2. In Dokploy dashboard, click "Redeploy"
3. Monitor deployment process
### Database Backups
```bash
# Create backup
docker exec quantumtasks-ai_db_1 pg_dump -U postgres quantumtasks_ai > backup.sql
# Restore backup
docker exec -i quantumtasks-ai_db_1 psql -U postgres quantumtasks_ai < backup.sql
```
### Scaling
- **Horizontal**: Add more web service replicas in docker-compose.yml
- **Vertical**: Increase container resource limits in Dokploy
## 🌟 Production Checklist
Before going live:
- [ ] Set strong SECRET_KEY (50+ random characters)
- [ ] Configure email settings (Gmail App Password recommended)
- [ ] Set up Stripe payment keys (live keys for production)
- [ ] Configure AI API keys (OpenAI, Groq, etc.)
- [ ] Test all core functionality
- [ ] Set up database backups
- [ ] Monitor error logs
- [ ] Configure domain SSL certificate
## 📞 Support
If you encounter issues:
1. Check application logs first
2. Verify environment variables
3. Test database connectivity
4. Check domain DNS settings
5. Review nginx configuration
---
**Deployment Target**: https://ai.quantumtaskai.com
**Last Updated**: 2025-09-06
**Status**: Ready for Production

308
DOKPLOY_SETUP_GUIDE.md Normal file
View File

@ -0,0 +1,308 @@
# Complete Dokploy Configuration Guide
## Hosting Quantum Tasks AI on ai.quantumtaskai.com
This guide walks you through the exact steps to configure your project in Dokploy.
---
## 🔧 Step 1: Access Dokploy Dashboard
1. **Open your browser** and navigate to your Dokploy dashboard:
```
https://your-dokploy-server.com
```
2. **Login** with your Dokploy credentials
---
## 🆕 Step 2: Create New Project
1. **Click "Create Project"** or the **"+"** button in the dashboard
2. **Choose Project Type**:
- Select **"Docker Compose"** (this is important!)
- NOT "Application" or "Database" - we need Compose for multiple services
3. **Project Configuration**:
```
Project Name: quantumtasks-ai
Description: Quantum Tasks AI Marketplace
```
---
## 📁 Step 3: Connect Git Repository
1. **Repository Source**: Choose **"Git Repository"**
2. **Repository URL**: Enter your repository URL:
```
https://github.com/your-username/quantumtaskai-caprover.git
```
3. **Branch**: Set to `main` or `master` (whatever your default branch is)
4. **Authentication** (if private repo):
- Use **Personal Access Token** or **SSH Key**
- For GitHub: Settings → Developer settings → Personal access tokens
5. **Build Path**: Leave as `.` (root directory)
---
## 🐳 Step 4: Docker Compose Configuration
1. **Compose File Path**: Set to `docker-compose.yml`
2. **Build Context**: Set to `.` (root directory)
3. **Auto Deploy**: Enable this for automatic deployments on git push
---
## 🌐 Step 5: Domain Configuration
1. **Go to "Domains" tab** in your project
2. **Add Domain**:
```
Domain: ai.quantumtaskai.com
Port: 80 (nginx service will handle SSL)
```
3. **SSL Certificate**:
- Enable **"Generate SSL Certificate"**
- Choose **"Let's Encrypt"**
- This will automatically handle HTTPS
---
## ⚙️ Step 6: Environment Variables
**Go to "Environment" tab** and add these variables:
### 🔑 Essential Variables (REQUIRED)
```env
SECRET_KEY=your-django-secret-key-50-characters-minimum
DEBUG=false
ALLOWED_HOSTS=ai.quantumtaskai.com,*.quantumtaskai.com,quantumtaskai.com
CSRF_TRUSTED_ORIGINS=https://ai.quantumtaskai.com,https://quantumtaskai.com
```
### 🗄️ Neon Database Variable
```env
NEON_DATABASE_URL=postgresql://your_username:your_password@your_endpoint.neon.tech/quantumtasks_ai?sslmode=require
```
**📝 Get this from your Neon dashboard**: Project → Dashboard → Connection Details → Connection String
### 📧 Email Configuration (Required for user accounts)
```env
EMAIL_HOST_USER=your-email@gmail.com
EMAIL_HOST_PASSWORD=your-gmail-app-password
DEFAULT_FROM_EMAIL=Quantum Tasks AI <noreply@ai.quantumtaskai.com>
REQUIRE_EMAIL_VERIFICATION=true
```
### 💳 Payment Integration (Optional but recommended)
```env
STRIPE_SECRET_KEY=sk_live_your_stripe_secret_key_here
STRIPE_WEBHOOK_SECRET=whsec_your_webhook_secret_here
```
### 🤖 AI API Keys (Optional but needed for AI features)
```env
OPENAI_API_KEY=sk-your_openai_api_key_here
GROQ_API_KEY=gsk_your_groq_api_key_here
SERPAPI_API_KEY=your_serpapi_key_here
OPENWEATHER_API_KEY=your_weather_api_key_here
```
### 🔒 Security Settings
```env
SECURE_SSL_REDIRECT=true
SECURE_PROXY_SSL_HEADER=HTTP_X_FORWARDED_PROTO,https
COMPOSE_PROJECT_NAME=quantumtasks-ai
```
---
## 🚀 Step 7: Deploy the Project
1. **Review Configuration**:
- ✅ Docker Compose file: `docker-compose.yml`
- ✅ Domain: `ai.quantumtaskai.com`
- ✅ Environment variables set
- ✅ SSL enabled
2. **Click "Deploy"** button
3. **Monitor the Build Process**:
- Watch the logs in real-time
- Build process will:
- Clone your repository
- Build the Docker image
- Start all services (nginx, web, db)
- Run health checks
4. **Wait for "Healthy" Status**:
- All services should show green/healthy status
- This may take 3-5 minutes
---
## ✅ Step 8: Post-Deployment Configuration
### Initialize Database
Once deployment is complete, you need to set up the database:
1. **Access Container Terminal** in Dokploy:
- Go to your project → Services → web service
- Click "Terminal" or "Console"
2. **Run Database Migrations**:
```bash
python manage.py migrate
```
3. **Create Superuser**:
```bash
python manage.py createsuperuser
```
- Enter username, email, and password when prompted
4. **Collect Static Files** (if needed):
```bash
python manage.py collectstatic --noinput
```
---
## 🔍 Step 9: Verify Deployment
### Test Your Application:
1. **Health Check**:
```
https://ai.quantumtaskai.com/health/
```
Should return: `{"status": "healthy", ...}`
2. **Main Website**:
```
https://ai.quantumtaskai.com/
```
Should load your marketplace
3. **Admin Panel**:
```
https://ai.quantumtaskai.com/admin/
```
Login with your superuser credentials
4. **Check HTTPS Redirect**:
```
http://ai.quantumtaskai.com/
```
Should automatically redirect to HTTPS
---
## 🔧 Step 10: Configure DNS (If Not Done)
If your domain isn't pointing to Dokploy server yet:
1. **Get Your Server IP**:
- From your Dokploy dashboard or server provider
2. **Add DNS Record**:
```
Type: A
Name: ai
Value: YOUR_DOKPLOY_SERVER_IP
TTL: 300 (5 minutes)
```
3. **Wait for Propagation** (can take up to 24 hours, usually 5-10 minutes)
---
## 📊 Monitoring & Logs
### View Logs in Dokploy:
1. **Project Dashboard** → **Logs**
2. **Individual Service Logs**:
- `nginx`: Web server logs
- `web`: Django application logs
### Check Service Health:
- All services should show **"Healthy"** status
- If any service is unhealthy, check its logs
---
## 🚨 Common Issues & Solutions
### Issue 1: Build Fails
**Solution**:
- Check if all files are committed to git
- Verify `docker-compose.yml` is in repository root
- Check environment variables are set
### Issue 2: Domain Not Working
**Solution**:
- Verify DNS settings
- Check domain configuration in Dokploy
- Ensure SSL certificate generated successfully
### Issue 3: Database Connection Error
**Solution**:
- Verify `NEON_DATABASE_URL` is correctly formatted
- Check Neon database is running (visit neon.tech dashboard)
- Ensure connection string includes `?sslmode=require`
- Test connection from Neon dashboard SQL editor
### Issue 4: Static Files Not Loading
**Solution**:
- Run `python manage.py collectstatic --noinput` in container
- Check nginx service logs
- Verify volumes are properly mounted
---
## 🎯 Quick Checklist
Before deployment:
- [ ] Repository contains all required files
- [ ] Domain points to Dokploy server
- [ ] All environment variables configured
- [ ] Gmail app password created (for email)
- [ ] API keys obtained (OpenAI, Stripe, etc.)
After deployment:
- [ ] All services show "Healthy" status
- [ ] Database migrations completed
- [ ] Superuser account created
- [ ] Health check returns success
- [ ] Website loads correctly
- [ ] HTTPS redirect works
- [ ] Admin panel accessible
---
## 📞 Need Help?
If you encounter issues:
1. **Check Dokploy logs** first
2. **Verify all environment variables** are set correctly
3. **Test database connectivity** from web container
4. **Check domain DNS** propagation
5. **Review nginx configuration** for any errors
---
**Target URL**: https://ai.quantumtaskai.com
**Deployment Status**: Ready to Deploy ✅
Your Quantum Tasks AI marketplace will be live and accessible once these steps are completed!

View File

@ -1,32 +1,47 @@
# Use Python 3.11 slim image for better performance and smaller size
FROM python:3.11-slim FROM python:3.11-slim
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV DEBIAN_FRONTEND=noninteractive
# Set work directory
WORKDIR /app WORKDIR /app
# Install system dependencies # Install system dependencies
RUN apt-get update && apt-get install -y \ RUN apt-get update \
&& apt-get install -y --no-install-recommends \
postgresql-client \
gcc \ gcc \
python3-dev \
libpq-dev \ libpq-dev \
curl \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# Copy and install Python dependencies # Copy requirements first to leverage Docker cache
COPY requirements.txt . COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt RUN pip install --no-cache-dir -r requirements.txt
# Copy application code # Copy project files
COPY . . COPY . .
# Set environment variables # Create logs directory
ENV PYTHONUNBUFFERED=1 RUN mkdir -p logs
ENV SECRET_KEY="build-time-dummy-key-change-in-production"
# Collect static files # Collect static files
RUN python manage.py collectstatic --noinput RUN python manage.py collectstatic --noinput --settings=netcop_hub.settings
# Create directory for media files # Create non-root user for security
RUN mkdir -p /app/media RUN adduser --disabled-password --gecos '' appuser && chown -R appuser:appuser /app
USER appuser
# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8000/health/ || exit 1
# Expose port # Expose port
EXPOSE 80 EXPOSE 8000
# Run migrations and start server # Run gunicorn
CMD ["sh", "-c", "python manage.py migrate && gunicorn netcop_hub.wsgi:application --bind 0.0.0.0:80"] CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "2", "--timeout", "120", "--access-logfile", "-", "--error-logfile", "-", "netcop_hub.wsgi:application"]

View File

@ -1,29 +0,0 @@
FROM python:3.11-slim
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y \
gcc \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*
# Copy and install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY . .
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
SECRET_KEY="build-time-dummy-key-change-in-production"
# Collect static files
RUN python manage.py collectstatic --noinput
# Expose port
EXPOSE 80
# Start gunicorn
CMD ["gunicorn", "netcop_hub.wsgi:application", "--bind", "0.0.0.0:80"]

145
NEON_DOKPLOY_SUMMARY.md Normal file
View File

@ -0,0 +1,145 @@
# 🚀 Quantum Tasks AI - Dokploy + Neon Deployment Summary
## Perfect! Your configuration is now optimized for Neon database
### ✅ What's Been Updated for Neon:
1. **docker-compose.yml** - Removed PostgreSQL container, using external Neon DB
2. **Environment Variables** - Updated to use `NEON_DATABASE_URL`
3. **Deployment Guide** - Updated with Neon-specific instructions
4. **Generator Script** - New `generate_neon_env.py` for secure values
---
## 🎯 Your Environment Variables (Generated)
Copy these to your Dokploy environment settings:
```env
# 🔑 ESSENTIAL VARIABLES (Required)
SECRET_KEY=b+6h(2YAa#8NPRfHApILsw&A8m^yQU=QfPMBCCsjEx31-)sDZh
DEBUG=false
ALLOWED_HOSTS=ai.quantumtaskai.com,*.quantumtaskai.com,quantumtaskai.com
CSRF_TRUSTED_ORIGINS=https://ai.quantumtaskai.com,https://quantumtaskai.com
# 🗄️ NEON DATABASE (Replace with your actual connection string)
NEON_DATABASE_URL=postgresql://your_username:your_password@your_endpoint.neon.tech/quantumtasks_ai?sslmode=require
# 📧 EMAIL CONFIGURATION (Fill in your values)
EMAIL_HOST_USER=your-email@gmail.com
EMAIL_HOST_PASSWORD=your-gmail-app-password
DEFAULT_FROM_EMAIL=Quantum Tasks AI <noreply@ai.quantumtaskai.com>
REQUIRE_EMAIL_VERIFICATION=true
# 🔒 SECURITY SETTINGS
SECURE_SSL_REDIRECT=true
SECURE_PROXY_SSL_HEADER=HTTP_X_FORWARDED_PROTO,https
COMPOSE_PROJECT_NAME=quantumtasks-ai
```
---
## 🗄️ How to Get Your Neon Database URL
1. **Login to Neon**: Go to https://neon.tech
2. **Select/Create Project**: Choose your project or create a new one
3. **Get Connection String**:
- Go to **Dashboard** → **Connection Details**
- Copy the **Connection String**
- It should look like: `postgresql://username:password@ep-xxx.neon.tech/dbname?sslmode=require`
4. **Create Database** (if needed): Make sure you have a database named `quantumtasks_ai`
---
## 📋 Dokploy Configuration Steps
### Step 1: Create Project
- **Type**: Docker Compose
- **Name**: quantumtasks-ai
- **Repository**: Your GitHub repository URL
### Step 2: Configure Environment
Copy all the variables above to Dokploy's environment settings, making sure to:
- ✅ Replace `NEON_DATABASE_URL` with your actual Neon connection string
- ✅ Update email settings with your Gmail credentials
- ✅ Add API keys as needed (Stripe, OpenAI, etc.)
### Step 3: Set Domain
- **Domain**: ai.quantumtaskai.com
- **SSL**: Enable Let's Encrypt
- **Port**: 80
### Step 4: Deploy
Click **Deploy** and monitor the build process
---
## 🏗️ Simplified Architecture (with Neon)
```
Internet → Nginx (SSL/Proxy) → Django App → Neon PostgreSQL (Serverless)
Static Files (Volume)
```
**Benefits of using Neon:**
- ✅ No database container to manage
- ✅ Automatic backups and scaling
- ✅ Serverless PostgreSQL (pay for what you use)
- ✅ Built-in connection pooling
- ✅ Geographic distribution
- ✅ Branch databases for development
---
## 🔧 Post-Deployment Commands
After successful deployment, run these in Dokploy terminal:
```bash
# Initialize database tables
python manage.py migrate
# Create admin user
python manage.py createsuperuser
# Collect static files (if needed)
python manage.py collectstatic --noinput
```
---
## 🔍 Testing Your Deployment
1. **Health Check**: https://ai.quantumtaskai.com/health/
2. **Website**: https://ai.quantumtaskai.com/
3. **Admin**: https://ai.quantumtaskai.com/admin/
---
## 💡 Advantages of This Setup
- **🌍 Global Scale**: Neon provides global database distribution
- **💰 Cost Effective**: Pay only for database usage, not idle time
- **🔄 Auto Scaling**: Database scales automatically with traffic
- **🛡️ Secure**: SSL-only connections, managed security
- **📈 Performance**: Built-in connection pooling and caching
- **🔧 Simple**: No database container management needed
---
## 📁 Files Created/Updated
- ✅ `docker-compose.yml` - Simplified without DB container
- ✅ `Dockerfile` - Production-ready Django container
- ✅ `nginx.conf` - SSL + reverse proxy configuration
- ✅ `.env.neon` - Environment variables template
- ✅ `generate_neon_env.py` - Secure variable generator
- ✅ `DOKPLOY_SETUP_GUIDE.md` - Step-by-step deployment guide
- ✅ Django settings updated for ai.quantumtaskai.com
---
**🎉 You're ready to deploy to ai.quantumtaskai.com with Neon!**
The setup is now optimized for serverless database hosting with simplified container management.

1
WARP.md Symbolic link
View File

@ -0,0 +1 @@
CLAUDE.md

View File

@ -1,4 +0,0 @@
{
"schemaVersion": 2,
"dockerfilePath": "./Dockerfile.captain"
}

View File

@ -1,56 +0,0 @@
# Coolify Deployment Guide
## Quick Setup Steps
### 1. Create New Project in Coolify
- Go to your Coolify dashboard
- Create a new project
- Choose "Deploy from Git Repository"
- Connect your GitHub repository
### 2. Configure Environment Variables
Set these in Coolify's environment variables section:
```env
SECRET_KEY=your-secret-key-here-generate-50-random-characters
DEBUG=false
ALLOWED_HOSTS=your-coolify-domain.com
DATABASE_URL=postgresql://postgres:password@db:5432/quantumtasks
POSTGRES_DB=quantumtasks
POSTGRES_USER=postgres
POSTGRES_PASSWORD=your-secure-password
```
Optional variables:
```env
EMAIL_HOST_USER=your-email@gmail.com
EMAIL_HOST_PASSWORD=your-app-password
STRIPE_SECRET_KEY=sk_test_your_stripe_key
```
### 3. Database Setup
Coolify will automatically create a PostgreSQL database using the docker-compose.yml configuration.
### 4. Deploy
- Push your code to the connected repository
- Coolify will automatically build and deploy
- The app will be available on port 3000
## File Structure Created
- `Dockerfile` - Main container configuration
- `docker-compose.yml` - Multi-service setup with PostgreSQL
- `.env.example` - Updated environment variable template
## Features Included
- ✅ PostgreSQL database
- ✅ Static file serving with WhiteNoise
- ✅ Automatic migrations on startup
- ✅ Gunicorn production server
- ✅ Volume persistence for media files
## Post-Deployment
1. Create superuser: Access the container and run `python manage.py createsuperuser`
2. Configure domain in Coolify dashboard
3. Set up SSL certificate (Coolify handles this automatically)
Your Django app will be ready at your configured Coolify domain!

View File

@ -1,4 +1,6 @@
from django.shortcuts import render, redirect from django.shortcuts import render
from django.http import JsonResponse
from django.db import connection
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.contrib import messages from django.contrib import messages
from django.http import JsonResponse, Http404 from django.http import JsonResponse, Http404

49
docker-compose.yml Normal file
View File

@ -0,0 +1,49 @@
version: '3.8'
services:
web:
build: .
ports:
- "8000:8000"
environment:
- DEBUG=false
- ALLOWED_HOSTS=ai.quantumtaskai.com,*.quantumtaskai.com
- CSRF_TRUSTED_ORIGINS=https://ai.quantumtaskai.com
- DATABASE_URL=${NEON_DATABASE_URL}
- SECRET_KEY=${SECRET_KEY}
- EMAIL_HOST_USER=${EMAIL_HOST_USER}
- EMAIL_HOST_PASSWORD=${EMAIL_HOST_PASSWORD}
- STRIPE_SECRET_KEY=${STRIPE_SECRET_KEY}
- OPENAI_API_KEY=${OPENAI_API_KEY}
- GROQ_API_KEY=${GROQ_API_KEY}
- SERPAPI_API_KEY=${SERPAPI_API_KEY}
- OPENWEATHER_API_KEY=${OPENWEATHER_API_KEY}
volumes:
- static_volume:/app/staticfiles
- media_volume:/app/media
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/health/"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
nginx:
image: nginx:alpine
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
- static_volume:/var/www/static:ro
- media_volume:/var/www/media:ro
- /etc/letsencrypt:/etc/letsencrypt:ro
depends_on:
- web
restart: unless-stopped
volumes:
static_volume:
media_volume:

118
generate_env.py Normal file
View File

@ -0,0 +1,118 @@
#!/usr/bin/env python3
"""
Environment Variable Generator for Quantum Tasks AI Dokploy Deployment
Generates secure values for environment variables needed for deployment.
"""
import secrets
import string
import os
def generate_secret_key(length=50):
"""Generate a secure Django SECRET_KEY"""
characters = string.ascii_letters + string.digits + '!@#$%^&*(-_=+)'
return ''.join(secrets.choice(characters) for _ in range(length))
def generate_password(length=24):
"""Generate a secure password"""
characters = string.ascii_letters + string.digits
return ''.join(secrets.choice(characters) for _ in range(length))
def main():
print("🔐 Quantum Tasks AI - Environment Variable Generator")
print("=" * 60)
print()
print("📋 Copy these values to your Dokploy environment variables:")
print()
# Generate secure values
secret_key = generate_secret_key()
postgres_password = generate_password()
# Core Django settings
print("🔑 ESSENTIAL VARIABLES (Required):")
print(f"SECRET_KEY={secret_key}")
print("DEBUG=false")
print("ALLOWED_HOSTS=ai.quantumtaskai.com,*.quantumtaskai.com,quantumtaskai.com")
print("CSRF_TRUSTED_ORIGINS=https://ai.quantumtaskai.com,https://quantumtaskai.com")
print()
# Database settings
print("🗄️ DATABASE VARIABLES:")
print("POSTGRES_DB=quantumtasks_ai")
print(f"POSTGRES_PASSWORD={postgres_password}")
print(f"DATABASE_URL=postgresql://postgres:{postgres_password}@db:5432/quantumtasks_ai")
print()
# Email settings (user needs to fill these)
print("📧 EMAIL CONFIGURATION (Fill in your values):")
print("EMAIL_HOST_USER=your-email@gmail.com")
print("EMAIL_HOST_PASSWORD=your-gmail-app-password")
print("DEFAULT_FROM_EMAIL=Quantum Tasks AI <noreply@ai.quantumtaskai.com>")
print("REQUIRE_EMAIL_VERIFICATION=true")
print()
# Security settings
print("🔒 SECURITY SETTINGS:")
print("SECURE_SSL_REDIRECT=true")
print("SECURE_PROXY_SSL_HEADER=HTTP_X_FORWARDED_PROTO,https")
print("COMPOSE_PROJECT_NAME=quantumtasks-ai")
print()
print("💡 OPTIONAL VARIABLES (Configure as needed):")
print("# Payment Processing")
print("STRIPE_SECRET_KEY=sk_live_your_stripe_secret_key_here")
print("STRIPE_WEBHOOK_SECRET=whsec_your_webhook_secret_here")
print()
print("# AI APIs")
print("OPENAI_API_KEY=sk-your_openai_api_key_here")
print("GROQ_API_KEY=gsk_your_groq_api_key_here")
print("SERPAPI_API_KEY=your_serpapi_key_here")
print("OPENWEATHER_API_KEY=your_weather_api_key_here")
print()
# Save to file option
save_to_file = input("💾 Save these variables to .env.production file? (y/N): ").lower()
if save_to_file == 'y':
with open('.env.production', 'w') as f:
f.write("# Generated Environment Variables for Dokploy\n")
f.write("# Generated on: " + str(os.popen('date').read().strip()) + "\n\n")
f.write("# ESSENTIAL VARIABLES\n")
f.write(f"SECRET_KEY={secret_key}\n")
f.write("DEBUG=false\n")
f.write("ALLOWED_HOSTS=ai.quantumtaskai.com,*.quantumtaskai.com,quantumtaskai.com\n")
f.write("CSRF_TRUSTED_ORIGINS=https://ai.quantumtaskai.com,https://quantumtaskai.com\n\n")
f.write("# DATABASE VARIABLES\n")
f.write("POSTGRES_DB=quantumtasks_ai\n")
f.write(f"POSTGRES_PASSWORD={postgres_password}\n")
f.write(f"DATABASE_URL=postgresql://postgres:{postgres_password}@db:5432/quantumtasks_ai\n\n")
f.write("# EMAIL CONFIGURATION (Fill in your values)\n")
f.write("EMAIL_HOST_USER=your-email@gmail.com\n")
f.write("EMAIL_HOST_PASSWORD=your-gmail-app-password\n")
f.write("DEFAULT_FROM_EMAIL=Quantum Tasks AI <noreply@ai.quantumtaskai.com>\n")
f.write("REQUIRE_EMAIL_VERIFICATION=true\n\n")
f.write("# SECURITY SETTINGS\n")
f.write("SECURE_SSL_REDIRECT=true\n")
f.write("SECURE_PROXY_SSL_HEADER=HTTP_X_FORWARDED_PROTO,https\n")
f.write("COMPOSE_PROJECT_NAME=quantumtasks-ai\n\n")
f.write("# OPTIONAL VARIABLES (Configure as needed)\n")
f.write("# STRIPE_SECRET_KEY=sk_live_your_stripe_secret_key_here\n")
f.write("# OPENAI_API_KEY=sk-your_openai_api_key_here\n")
f.write("# GROQ_API_KEY=gsk_your_groq_api_key_here\n")
f.write("# SERPAPI_API_KEY=your_serpapi_key_here\n")
f.write("# OPENWEATHER_API_KEY=your_weather_api_key_here\n")
print("✅ Variables saved to .env.production")
print("⚠️ Remember to update EMAIL_HOST_USER and EMAIL_HOST_PASSWORD!")
print()
print("📝 Next Steps:")
print("1. Copy the essential variables to Dokploy environment settings")
print("2. Update email settings with your Gmail app password")
print("3. Add optional API keys as needed")
print("4. Deploy your project in Dokploy!")
print()
print("🌐 Your site will be live at: https://ai.quantumtaskai.com")
if __name__ == "__main__":
main()

122
generate_neon_env.py Normal file
View File

@ -0,0 +1,122 @@
#!/usr/bin/env python3
"""
Environment Variable Generator for Quantum Tasks AI Dokploy + Neon Deployment
Generates secure values for environment variables with Neon database integration.
"""
import secrets
import string
import os
def generate_secret_key(length=50):
"""Generate a secure Django SECRET_KEY"""
characters = string.ascii_letters + string.digits + '!@#$%^&*(-_=+)'
return ''.join(secrets.choice(characters) for _ in range(length))
def main():
print("🔐 Quantum Tasks AI - Environment Variable Generator (Neon Edition)")
print("=" * 70)
print()
print("📋 Copy these values to your Dokploy environment variables:")
print()
# Generate secure values
secret_key = generate_secret_key()
# Core Django settings
print("🔑 ESSENTIAL VARIABLES (Required):")
print(f"SECRET_KEY={secret_key}")
print("DEBUG=false")
print("ALLOWED_HOSTS=ai.quantumtaskai.com,*.quantumtaskai.com,quantumtaskai.com")
print("CSRF_TRUSTED_ORIGINS=https://ai.quantumtaskai.com,https://quantumtaskai.com")
print()
# Neon database settings
print("🗄️ NEON DATABASE VARIABLE:")
print("NEON_DATABASE_URL=postgresql://your_username:your_password@your_endpoint.neon.tech/quantumtasks_ai?sslmode=require")
print("# ☝️ Get this from your Neon dashboard: Database → Connection Details → Connection String")
print()
# Email settings (user needs to fill these)
print("📧 EMAIL CONFIGURATION (Fill in your values):")
print("EMAIL_HOST_USER=your-email@gmail.com")
print("EMAIL_HOST_PASSWORD=your-gmail-app-password")
print("DEFAULT_FROM_EMAIL=Quantum Tasks AI <noreply@ai.quantumtaskai.com>")
print("REQUIRE_EMAIL_VERIFICATION=true")
print()
# Security settings
print("🔒 SECURITY SETTINGS:")
print("SECURE_SSL_REDIRECT=true")
print("SECURE_PROXY_SSL_HEADER=HTTP_X_FORWARDED_PROTO,https")
print("COMPOSE_PROJECT_NAME=quantumtasks-ai")
print()
print("💡 OPTIONAL VARIABLES (Configure as needed):")
print("# Payment Processing")
print("STRIPE_SECRET_KEY=sk_live_your_stripe_secret_key_here")
print("STRIPE_WEBHOOK_SECRET=whsec_your_webhook_secret_here")
print()
print("# AI APIs")
print("OPENAI_API_KEY=sk-your_openai_api_key_here")
print("GROQ_API_KEY=gsk_your_groq_api_key_here")
print("SERPAPI_API_KEY=your_serpapi_key_here")
print("OPENWEATHER_API_KEY=your_weather_api_key_here")
print()
print("🎯 HOW TO GET YOUR NEON DATABASE URL:")
print("1. Go to https://neon.tech and login to your account")
print("2. Select your project (or create one)")
print("3. Go to 'Dashboard''Connection Details'")
print("4. Copy the 'Connection String' (it looks like the format above)")
print("5. Make sure the database name matches 'quantumtasks_ai' or update accordingly")
print()
# Save to file option
save_to_file = input("💾 Save these variables to .env.neon file? (y/N): ").lower()
if save_to_file == 'y':
with open('.env.neon', 'w') as f:
f.write("# Generated Environment Variables for Dokploy + Neon\n")
f.write("# Generated on: " + str(os.popen('date').read().strip()) + "\n\n")
f.write("# ESSENTIAL VARIABLES\n")
f.write(f"SECRET_KEY={secret_key}\n")
f.write("DEBUG=false\n")
f.write("ALLOWED_HOSTS=ai.quantumtaskai.com,*.quantumtaskai.com,quantumtaskai.com\n")
f.write("CSRF_TRUSTED_ORIGINS=https://ai.quantumtaskai.com,https://quantumtaskai.com\n\n")
f.write("# NEON DATABASE VARIABLE\n")
f.write("NEON_DATABASE_URL=postgresql://your_username:your_password@your_endpoint.neon.tech/quantumtasks_ai?sslmode=require\n")
f.write("# Get this from Neon dashboard: Database → Connection Details\n\n")
f.write("# EMAIL CONFIGURATION (Fill in your values)\n")
f.write("EMAIL_HOST_USER=your-email@gmail.com\n")
f.write("EMAIL_HOST_PASSWORD=your-gmail-app-password\n")
f.write("DEFAULT_FROM_EMAIL=Quantum Tasks AI <noreply@ai.quantumtaskai.com>\n")
f.write("REQUIRE_EMAIL_VERIFICATION=true\n\n")
f.write("# SECURITY SETTINGS\n")
f.write("SECURE_SSL_REDIRECT=true\n")
f.write("SECURE_PROXY_SSL_HEADER=HTTP_X_FORWARDED_PROTO,https\n")
f.write("COMPOSE_PROJECT_NAME=quantumtasks-ai\n\n")
f.write("# OPTIONAL VARIABLES (Configure as needed)\n")
f.write("# STRIPE_SECRET_KEY=sk_live_your_stripe_secret_key_here\n")
f.write("# OPENAI_API_KEY=sk-your_openai_api_key_here\n")
f.write("# GROQ_API_KEY=gsk_your_groq_api_key_here\n")
f.write("# SERPAPI_API_KEY=your_serpapi_key_here\n")
f.write("# OPENWEATHER_API_KEY=your_weather_api_key_here\n")
print("✅ Variables saved to .env.neon")
print("⚠️ Remember to:")
print(" - Update NEON_DATABASE_URL with your actual Neon connection string")
print(" - Update EMAIL_HOST_USER and EMAIL_HOST_PASSWORD")
print()
print("📝 Next Steps:")
print("1. Get your Neon database connection string from neon.tech")
print("2. Copy all variables to Dokploy environment settings")
print("3. Update email settings with your Gmail app password")
print("4. Add optional API keys as needed")
print("5. Deploy your project in Dokploy!")
print()
print("🌐 Your site will be live at: https://ai.quantumtaskai.com")
print("🗄️ Database: Neon Serverless PostgreSQL (no local DB container needed!)")
if __name__ == "__main__":
main()

View File

@ -54,7 +54,7 @@ if missing_vars:
# SECURITY WARNING: don't run with debug turned on in production! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = config('DEBUG', default=True, cast=bool) DEBUG = config('DEBUG', default=True, cast=bool)
ALLOWED_HOSTS = config('ALLOWED_HOSTS', default='localhost,127.0.0.1,testserver,quantumtaskai.com,www.quantumtaskai.com').split(',') ALLOWED_HOSTS = config('ALLOWED_HOSTS', default='localhost,127.0.0.1,testserver,quantumtaskai.com,www.quantumtaskai.com,ai.quantumtaskai.com').split(',')
# CapRover auto-detection # CapRover auto-detection
if config('CAPROVER_GIT_COMMIT_SHA', default=''): if config('CAPROVER_GIT_COMMIT_SHA', default=''):
@ -68,6 +68,9 @@ if config('DOKPLOY_PROJECT_NAME', default=''):
if config('RAILWAY_ENVIRONMENT', default=''): if config('RAILWAY_ENVIRONMENT', default=''):
# Use production domain for email verification links # Use production domain for email verification links
SITE_URL = 'https://www.quantumtaskai.com' SITE_URL = 'https://www.quantumtaskai.com'
elif config('DOKPLOY_PROJECT_NAME', default='') or config('COMPOSE_PROJECT_NAME', default=''):
# Use ai subdomain for Dokploy deployment
SITE_URL = 'https://ai.quantumtaskai.com'
else: else:
SITE_URL = config('SITE_URL', default='http://localhost:8000') SITE_URL = config('SITE_URL', default='http://localhost:8000')
@ -337,7 +340,7 @@ EMAIL_USE_TLS = config('EMAIL_USE_TLS', default=True, cast=bool)
EMAIL_HOST_USER = config('EMAIL_HOST_USER', default='') EMAIL_HOST_USER = config('EMAIL_HOST_USER', default='')
EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD', default='') EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD', default='')
EMAIL_FILE_PATH = config('EMAIL_FILE_PATH', default='/tmp/app-messages') EMAIL_FILE_PATH = config('EMAIL_FILE_PATH', default='/tmp/app-messages')
DEFAULT_FROM_EMAIL = config('DEFAULT_FROM_EMAIL', default='Quantum Tasks AI <noreply@quantumtaskai.com>') DEFAULT_FROM_EMAIL = config('DEFAULT_FROM_EMAIL', default='Quantum Tasks AI <noreply@ai.quantumtaskai.com>')
# Email timeout settings for production stability # Email timeout settings for production stability
EMAIL_TIMEOUT = 30 EMAIL_TIMEOUT = 30
@ -364,7 +367,7 @@ if config('RAILWAY_ENVIRONMENT', default=''):
CSRF_TRUSTED_ORIGINS.append(f'https://{railway_url}') CSRF_TRUSTED_ORIGINS.append(f'https://{railway_url}')
# Also add production domains (both www and non-www) # Also add production domains (both www and non-www)
CSRF_TRUSTED_ORIGINS.extend(['https://quantumtaskai.com', 'https://www.quantumtaskai.com']) CSRF_TRUSTED_ORIGINS.extend(['https://quantumtaskai.com', 'https://www.quantumtaskai.com', 'https://ai.quantumtaskai.com'])
# Railway-specific optimizations # Railway-specific optimizations
USE_X_FORWARDED_HOST = True USE_X_FORWARDED_HOST = True
@ -374,6 +377,19 @@ if config('RAILWAY_ENVIRONMENT', default=''):
if 'default' in DATABASES: if 'default' in DATABASES:
DATABASES['default']['CONN_MAX_AGE'] = 600 # 10 minutes connection pooling DATABASES['default']['CONN_MAX_AGE'] = 600 # 10 minutes connection pooling
# Add Dokploy configuration if running on Dokploy
if config('DOKPLOY_PROJECT_NAME', default='') or config('COMPOSE_PROJECT_NAME', default=''):
# Add ai.quantumtaskai.com to trusted origins
CSRF_TRUSTED_ORIGINS.extend(['https://ai.quantumtaskai.com', 'https://quantumtaskai.com', 'https://www.quantumtaskai.com'])
# Dokploy-specific optimizations
USE_X_FORWARDED_HOST = True
USE_X_FORWARDED_PORT = True
# Database connection optimization for PostgreSQL
if 'default' in DATABASES:
DATABASES['default']['CONN_MAX_AGE'] = 600 # 10 minutes connection pooling
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# Default primary key field type # Default primary key field type

128
nginx.conf Normal file
View File

@ -0,0 +1,128 @@
events {
worker_connections 1024;
}
http {
upstream web {
server web:8000;
}
# Rate limiting
limit_req_zone $binary_remote_addr zone=web:10m rate=10r/s;
limit_req_zone $binary_remote_addr zone=api:10m rate=30r/s;
# MIME types
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Security headers
add_header X-Frame-Options DENY always;
add_header X-Content-Type-Options nosniff always;
add_header X-XSS-Protection "1; mode=block" always;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
# Logging
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log warn;
# Gzip compression
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_proxied any;
gzip_comp_level 6;
gzip_types
text/plain
text/css
text/xml
text/javascript
application/json
application/javascript
application/xml+rss
application/atom+xml;
# HTTP to HTTPS redirect
server {
listen 80;
server_name ai.quantumtaskai.com;
return 301 https://$server_name$request_uri;
}
# HTTPS server
server {
listen 443 ssl http2;
server_name ai.quantumtaskai.com;
# SSL configuration
ssl_certificate /etc/letsencrypt/live/ai.quantumtaskai.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/ai.quantumtaskai.com/privkey.pem;
# SSL security settings
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers off;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
# Security headers specific to HTTPS
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
# Client max body size
client_max_body_size 100M;
# Static files
location /static/ {
alias /var/www/static/;
expires 1y;
add_header Cache-Control "public, immutable";
}
# Media files
location /media/ {
alias /var/www/media/;
expires 1y;
add_header Cache-Control "public";
}
# API endpoints with higher rate limit
location /api/ {
limit_req zone=api burst=10 nodelay;
proxy_pass http://web;
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;
proxy_redirect off;
}
# Health check endpoint
location /health/ {
proxy_pass http://web;
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;
access_log off;
}
# Main application
location / {
limit_req zone=web burst=5 nodelay;
proxy_pass http://web;
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;
proxy_redirect off;
# Timeouts
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
}
}
}