Quick reference for the most common deployment issues.
Symptom: nginx returns 502 Bad Gateway for /api/* requests.
Causes & fixes:
- gunicorn not running:
sudo systemctl status texttosql sudo journalctl -u texttosql -n 50 --no-pager sudo systemctl restart texttosql
- Wrong bind address in service file: Confirm
--bind 127.0.0.1:8000intexttosql.service. - Port 8000 not listening:
ss -tlnp | grep 8000 - nginx upstream misconfigured: Verify
proxy_pass http://127.0.0.1:8000;in nginx.conf. - Worker timeout on slow LLM call: Increase
--timeoutin ExecStart andproxy_read_timeoutin nginx.conf.
Symptom: ssh: connect to host X.X.X.X port 22: Connection refused
Causes & fixes:
- EC2 security group blocks port 22: Add inbound rule for TCP/22 from your IP.
- Instance still booting: Wait 2 minutes after launch, then retry.
- Wrong key pair: Ensure you're using
~/.ssh/your-key.pemand the key matches the instance. - Instance stopped: Check EC2 console → Instance State → Start.
ssh -i ~/.ssh/your-key.pem ubuntu@<public-ip>
Symptom: ValueError: Collection 'schema_index' does not exist. in gunicorn logs.
Causes & fixes:
- build_index.py was never run:
cd /opt/querymind-sql source venv/bin/activate && source .env python -m agent.build_index sudo systemctl restart texttosql
- Wrong CHROMA_PERSIST_DIR: The path in
.envmust match wherebuild_index.pywrote files. Use absolute paths. - Permission issue: Ensure
ubuntuuser ownschroma_store/:chown -R ubuntu:ubuntu /opt/querymind-sql/chroma_store
Symptom: openai.AuthenticationError: 401 Unauthorized in logs.
Causes & fixes:
- OPENAI_API_KEY not set or wrong: Check
.envfile:grep OPENAI_API_KEY /opt/querymind-sql/.env
- Key has been revoked: Generate a new key at https://platform.openai.com/api-keys.
- EnvironmentFile not loaded: Confirm
EnvironmentFile=/opt/querymind-sql/.envin the service file and restart.
Symptom: openai.RateLimitError: 429 Too Many Requests
Causes & fixes:
- Hit requests-per-minute limit: Implement exponential backoff. LangChain does this automatically with
max_retries. - Exceeded monthly quota: Check usage at https://platform.openai.com/usage and upgrade plan.
- Too many concurrent workers: Reduce gunicorn
--workersto 2 to lower parallel OpenAI calls.
Symptom: [CRITICAL] WORKER TIMEOUT in gunicorn logs; client gets 502.
Causes & fixes:
- LLM call taking too long: GPT-4o with a long prompt can take 30-60s. Increase timeouts:
texttosql.service: change--timeout 120to--timeout 180nginx.conf: changeproxy_read_timeout 120stoproxy_read_timeout 180s
- ChromaDB slow cold start: First request after deploy is slow. Use a readiness check.
- DB query on large dataset: Add
LIMIT 1000to generated SQL (already enforced in the prompt).
Symptom: Browser shows blank page; no errors in nginx logs.
Causes & fixes:
- Frontend not built: Run
npm run buildin thefrontend/directory. - nginx root path wrong: Confirm
root /opt/querymind-sql/frontend/dist;in nginx.conf. - SPA routing not configured: Ensure
try_files $uri $uri/ /index.html;is in nginx location block. - JavaScript error in browser console: Open DevTools → Console tab to see the actual error.
- Old dist/ cached: Hard reload with
Ctrl+Shift+RorCmd+Shift+R.# Rebuild frontend cd /opt/querymind-sql/frontend && npm run build sudo systemctl reload nginx
For a complete step-by-step production deployment walkthrough on Ubuntu and AWS EC2, please refer to the Deployment Guide.