Production Deployment Guide

Deploy BlueSentinel in a production environment with Gunicorn, Nginx, and systemd.


Architecture

A production deployment consists of:

Internet → Nginx (TLS) → Gunicorn (port 5100) → Flask App → PostgreSQL

Server Setup

1. Create a Dedicated User

bash
sudo useradd -r -m -s /bin/bash bluesentinel
sudo mkdir -p /opt/BlueSentinel
sudo chown bluesentinel:bluesentinel /opt/BlueSentinel

2. Install Application

bash
sudo -u bluesentinel bash
cd /opt/BlueSentinel
git clone https://github.com/your-org/BlueSentinel.git .
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

3. Configure Environment

Create /opt/BlueSentinel/.env:

bash
DATABASE_URL=postgresql://bluesentinel:password@localhost/bluesentinel
SECRET_KEY=your-64-char-random-secret
JWT_SECRET=your-64-char-random-jwt-secret
PORT=5100
CORS_ORIGINS=https://bluesentinel.yourcompany.com

4. Systemd Service

Create /etc/systemd/system/bluesentinel.service:

[Unit]
Description=BlueSentinel Central Server
After=network.target postgresql.service

[Service]
Type=simple
User=bluesentinel
WorkingDirectory=/opt/BlueSentinel
EnvironmentFile=/opt/BlueSentinel/.env
ExecStart=/opt/BlueSentinel/venv/bin/gunicorn -w 4 -b 127.0.0.1:5100 --timeout 120 "central_server.app:create_app()"
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target
bash
sudo systemctl daemon-reload
sudo systemctl enable bluesentinel
sudo systemctl start bluesentinel

5. Nginx Reverse Proxy

server {
    listen 443 ssl http2;
    server_name bluesentinel.yourcompany.com;

    ssl_certificate /etc/letsencrypt/live/bluesentinel.yourcompany.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/bluesentinel.yourcompany.com/privkey.pem;

    location / {
        proxy_pass http://127.0.0.1:5100;
        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_read_timeout 120s;
    }
}

server {
    listen 80;
    server_name bluesentinel.yourcompany.com;
    return 301 https://$server_name$request_uri;
}

Health Monitoring

bash
curl -f https://bluesentinel.yourcompany.com/health

Expected response:

json
{
  "status": "healthy",
  "database": "connected",
  "version": "1.0.0"
}

Security Checklist

  • Change the default admin password immediately
  • Use strong, unique values for SECRET_KEY and JWT_SECRET
  • Enable TLS with a valid certificate (Let's Encrypt recommended)
  • Restrict PostgreSQL access to localhost
  • Set CORS_ORIGINS to your specific domain
  • Enable firewall: only allow ports 443 (HTTPS) and 22 (SSH)
  • Set up automated database backups