Guide to Configure Logto Auth Server on Cloud VPS: OIDC/OAuth2 Identity Management Solution for New Apps
Step-by-step guide to configure Logto Auth Server on Cloud VPS for identity management using OIDC/OAuth2, optimized for new applications with easy integration and high security.
Introduction to Logto and Identity Management Solution
Logto is an open-source identity management platform designed to help developers build authentication and identity management systems quickly, securely, and easily. With OIDC (OpenID Connect) and OAuth 2.0 standards, Logto enables applications to authenticate users, manage roles, assign permissions, and integrate with third-party systems.
In new application environments, deploying a self-hosted authentication system allows full control over user data, reduces dependency on third-party services, and optimizes costs. Cloud VPS is ideal for deploying Logto due to its scalability, high RAM and CPU resources, and SSH access capabilities.
Prerequisites Before Configuration
- Cloud VPS: Use a VPS with at least 4GB RAM, 2 CPU cores, and 50GB SSD (minimum). Recommended: High-RAM Cloud VPS for Self-Hosted LLMs & API Gateways.
- OS: Ubuntu 22.04 LTS or Debian 11.
- Domain: A dedicated domain (e.g.,
auth.yourdomain.com) with DNS A record pointing to the VPS IP. - SSL/TLS: Free SSL certificate from Let's Encrypt (automatically supported via Certbot).
- Tools: SSH client, Docker, Docker Compose, and Git.
Configure Logto Auth Server on Cloud VPS
We will use Docker to deploy Logto quickly and manage it easily.
Step 1: Install Docker and Docker Compose
On Ubuntu VPS, run the following commands:
# Update system
sudo apt update && sudo apt upgrade -y
# Install Docker
sudo apt install -y docker.io docker-compose
# Enable Docker to start on boot
sudo systemctl enable docker
sudo systemctl start docker
Step 2: Create Logto Project
Create a directory and download the Logto configuration:
mkdir logto && cd logto
wget https://raw.githubusercontent.com/logto-io/logto/main/docker-compose.yml
Step 3: Configure Environment
Create a `.env` file for configuration:
# .env
LOGTO_DOMAIN=auth.yourdomain.com
[email protected]
LOGTO_ADMIN_PASSWORD=YourSecurePassword123!
LOGTO_DB_TYPE=sqlite
LOGTO_DB_PATH=./data/logto.db
LOGTO_LOG_LEVEL=info
Step 4: Start the Service
docker-compose up -d
Step 5: Configure Reverse Proxy (Nginx)
Logto needs HTTPS access. Install Nginx and Certbot:
sudo apt install -y nginx certbot
sudo certbot certonly --nginx -d auth.yourdomain.com
Add Nginx configuration in /etc/nginx/sites-available/auth.yourdomain.com:
server {
listen 80;
server_name auth.yourdomain.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name auth.yourdomain.com;
ssl_certificate /etc/letsencrypt/live/auth.yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/auth.yourdomain.com/privkey.pem;
location / {
proxy_pass http://localhost:3000;
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;
}
}
Testing and Verification
After startup, access https://auth.yourdomain.com to reach the Logto admin interface.
Log in with the configured email and password. Then, create a new application under Applications to obtain the Client ID and Client Secret.
Integrate with New Applications
Your application can integrate with Logto using SDKs or APIs. Example using OAuth 2.0:
POST /oauth/token HTTP/1.1
Host: auth.yourdomain.com
Content-Type: application/x-www-form-urlencoded
grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET
Optimization and Security Solutions
- Performance optimization: Use Redis as a token cache to reduce database load.
- Security: Always use HTTPS, configure CORS, and limit admin access by IP.
- Backup: Regularly back up the database using
docker-compose down -v. - Monitoring: Connect to Prometheus and Grafana to monitor activity.
Troubleshooting
- Cannot access admin page: Check Docker logs:
docker-compose logs -f logto. - SSL certificate error: Run
certbot renewor verify DNS settings. - Token authentication failure: Verify Client ID/Secret and OAuth2 configuration.
References
High-RAM Cloud VPS Plans Optimized for AI, Databases & Cache
Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.
VPS-4E
10% VAT included
- CPU: 4 vCPU
- RAM: 8 GB
- SSD: 50 GB NVMe
