> ## Documentation Index
> Fetch the complete documentation index at: https://docs.vantagewealth.app/llms.txt
> Use this file to discover all available pages before exploring further.

# EC2 Deployment

> Deploy the FastAPI backend to AWS EC2 with nginx and systemd.

## Launch an EC2 instance

1. Go to AWS EC2 → Launch Instance
2. Choose **Ubuntu 22.04 LTS** (free tier eligible: t2.micro / t3.micro)
3. Add security group rules: allow inbound on port 22 (SSH) and 443 (HTTPS)
4. Download your key pair

***

## Initial server setup

```bash theme={null}
ssh -i your-key.pem ubuntu@your-ec2-ip

# Update and install dependencies
sudo apt update && sudo apt upgrade -y
sudo apt install python3.11 python3.11-venv nginx certbot python3-certbot-nginx -y
```

***

## Deploy the backend

```bash theme={null}
git clone https://github.com/rmurarishetti/vantage.git
cd vantage/backend

python3.11 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

# Create .env with your credentials
cp .env.example .env
nano .env
```

***

## Configure systemd

Create `/etc/systemd/system/vantage.service`:

```ini theme={null}
[Unit]
Description=Vantage Wealth FastAPI Backend
After=network.target

[Service]
User=ubuntu
WorkingDirectory=/home/ubuntu/vantage/backend
Environment="PATH=/home/ubuntu/vantage/backend/venv/bin"
ExecStart=/home/ubuntu/vantage/backend/venv/bin/uvicorn main:app --host 0.0.0.0 --port 8000 --workers 2
Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target
```

```bash theme={null}
sudo systemctl enable vantage
sudo systemctl start vantage
sudo systemctl status vantage
```

***

## Configure nginx + HTTPS

```bash theme={null}
# /etc/nginx/sites-available/vantage
server {
    server_name api.yourdomain.com;

    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        # Required for SSE streaming
        proxy_buffering off;
        proxy_cache off;
        proxy_read_timeout 300s;
    }
}
```

```bash theme={null}
sudo ln -s /etc/nginx/sites-available/vantage /etc/nginx/sites-enabled/
sudo certbot --nginx -d api.yourdomain.com
sudo systemctl reload nginx
```

Update your `API_BASE_URL` in `.env.json` to `https://api.yourdomain.com`.
