12 - Ubuntu Server Installation

Overview

This guide covers deploying OpenAlgo on an Ubuntu server (20.04/22.04 LTS) with Nginx reverse proxy, systemd services, and SSL configuration for production use.

Architecture Diagram

┌──────────────────────────────────────────────────────────────────────────────┐
│                        Ubuntu Server Architecture                            │
└──────────────────────────────────────────────────────────────────────────────┘

                         Internet


┌─────────────────────────────────────────────────────────────────────────────┐
│                          Nginx (Reverse Proxy)                               │
│                          Port 80/443                                         │
│                                                                              │
│  ┌─────────────────────────────────────────────────────────────────────┐   │
│  │  - SSL termination (Let's Encrypt)                                   │   │
│  │  - HTTP → HTTPS redirect                                             │   │
│  │  - WebSocket upgrade support                                         │   │
│  │  - Static file serving                                               │   │
│  └─────────────────────────────────────────────────────────────────────┘   │
└─────────────────────────────────────────────────────────────────────────────┘
                    │                       │
                    ▼                       ▼
┌─────────────────────────────────────────────────────┐
│           OpenAlgo (Gunicorn + WebSocket)           │
│                                                     │
│  Flask App ─────────── localhost:5000               │
│  WebSocket Thread ──── localhost:8765               │
│                                                     │
│  systemd: openalgo                                  │
└─────────────────────────────────────────────────────┘


┌─────────────────────────────────────────────────────────────────────────────┐
│                          File System                                         │
│                                                                              │
│  /opt/openalgo/                                                             │
│  ├── .venv/              # Virtual environment                              │
│  ├── db/                 # SQLite databases                                 │
│  ├── log/                # Application logs                                 │
│  ├── strategies/         # User strategies                                  │
│  ├── .env                # Configuration                                    │
│  └── app.py              # Main application                                 │
└─────────────────────────────────────────────────────────────────────────────┘

Prerequisites

Installation Steps

1. Clone Repository

2. Setup Python Environment

3. Configure Environment

4. Build Frontend

5. Create Systemd Service

Note: The WebSocket server runs as a thread inside the main app (port 8765), so only ONE systemd service is needed.

Important: Use -w 1 (single worker) for WebSocket compatibility.

6. Set Permissions

7. Configure Nginx

8. Enable Service

9. Setup SSL (Let's Encrypt)

Service Management

Firewall Configuration

Update Procedure

Troubleshooting

Issue
Solution

502 Bad Gateway

Check if OpenAlgo service is running: systemctl status openalgo

WebSocket fails

Check Nginx /ws proxy config and service logs

Permission denied

Verify www-data ownership: chown -R www-data:www-data /opt/openalgo

SSL error

Renew certificates: sudo certbot renew

Key Files Reference

File
Purpose

/etc/systemd/system/openalgo.service

Main service (includes WebSocket)

/etc/nginx/sites-available/openalgo

Nginx config

/opt/openalgo/.env

Application config

/var/log/nginx/

Nginx logs

Note: There is no separate openalgo-ws.service. The WebSocket server runs as a thread inside the main Flask application on port 8765.

Last updated