1st Services Logo
Guides & Tutorials

Deploy a Full-Stack App with VPS & PostgreSQL

End-to-end tutorial on launching a high-performance VPS, configuring Nginx, and connecting to 1st Managed PostgreSQL.

Deploy a Full-Stack App with 1st VPS & PostgreSQL

In this tutorial, you will learn how to provision a high-performance 1st Cloud VPS, attach a 1st Managed PostgreSQL instance, and deploy a containerized application with automated SSL.


Architecture Overview

graph LR
  User[User Browser / Client] -->|HTTPS :443| Nginx[Nginx Reverse Proxy]
  Nginx -->|Port :3000| App[Dockerized Web App on 1st VPS]
  App -->|Encrypted TLS / VPC| DB[(1st Managed PostgreSQL)]

Step 1: Provision Resources via API

deploy-infra.sh
# 1. Create a private VPC
VPC_ID=$(curl -s -X POST https://api.1st-services.com/v1/networking/vpcs \
  -H "Authorization: Bearer $FIRST_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "app-vpc", "region": "us-east-1"}' | jq -r .data.id)

# 2. Launch Managed PostgreSQL in the VPC
DB_URI=$(curl -s -X POST https://api.1st-services.com/v1/databases \
  -H "Authorization: Bearer $FIRST_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"name\":\"app-db\",\"engine\":\"postgresql\",\"version\":\"16\",\"plan\":\"db-standard-2\",\"vpc_id\":\"$VPC_ID\"}" | jq -r .data.connection_uri)

# 3. Launch VPS in the same VPC
curl -X POST https://api.1st-services.com/v1/vps/instances \
  -H "Authorization: Bearer $FIRST_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{
    \"name\": \"app-web-01\",
    \"plan\": \"vps-standard-2\",
    \"region\": \"us-east-1\",
    \"image\": \"ubuntu-24.04-lts\",
    \"vpc_id\": \"$VPC_ID\"
  }"

Step 2: Configure Application Environment

Connect to your VPS instance via SSH:

Terminal
ssh root@<VPS_IP_ADDRESS>

Create your .env configuration file pointing securely to your 1st Managed PostgreSQL instance:

/opt/app/.env
NODE_ENV=production
PORT=3000
DATABASE_URL="postgresql://firstadmin:P4ssw0rd!@pg-cluster-9918231.db.1st-services.com:5432/defaultdb?sslmode=require"

Step 3: Run with Docker Compose

/opt/app/docker-compose.yml
version: '3.8'

services:
  web:
    image: ghcr.io/myorg/myapp:latest
    restart: always
    env_file: .env
    ports:
      - "127.0.0.1:3000:3000"

  caddy:
    image: caddy:2-alpine
    restart: always
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
      - caddy_data:/data
      - caddy_config:/config

volumes:
  caddy_data:
  caddy_config:
/opt/app/Caddyfile
api.yourdomain.com {
    reverse_proxy web:3000
}

Start the containers:

Terminal
docker compose up -d

Your full-stack application is now live, secured with automated TLS certificates, and connected to high-performance managed database infrastructure.

Copyright © 2026