Whether your API is written in Node.js, Python, Go, Java or PHP, hosting it on a VPS follows the same pattern. The framework-specific part is short; most of the work is making the service reliable, secure and observable. This guide covers that shared part. For framework details, see our guides for FastAPI, Go, Spring Boot and Laravel.
Architecture
client ─HTTPS─▶ Nginx (api.example.com:443)
│ TLS, rate limits, body size, timeouts
▼
API process (127.0.0.1:8000) ──▶ database (local socket / 127.0.0.1)
Only ports 22, 80 and 443 are open to the internet; the API and database listen on localhost.
Step 1: DNS and Server Basics
Point an A record for api.example.com at the VPS. Secure the server first: SSH keys only, a firewall that allows SSH, HTTP and HTTPS, and automatic security updates (see our SSH key and UFW guides).
Step 2: Run the API as a Service
Create a dedicated user and a systemd unit so the API starts on boot and restarts after crashes:
sudo useradd --system --create-home --shell /usr/sbin/nologin api
# /etc/systemd/system/api.service
[Unit]
Description=REST API
After=network.target
[Service]
User=api
WorkingDirectory=/srv/api/current
EnvironmentFile=/etc/api/env
ExecStart=/srv/api/current/start.sh
Restart=on-failure
RestartSec=3
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now api
curl -s http://127.0.0.1:8000/health
Keep secrets (database password, signing keys) in /etc/api/env with permissions 600, never in the repository. start.sh is whatever starts your server, for example a Uvicorn, Gunicorn, Node.js or Java command bound to 127.0.0.1:8000.
Step 3: Nginx Reverse Proxy
# /etc/nginx/conf.d/ratelimit.conf
limit_req_zone $binary_remote_addr zone=api_per_ip:10m rate=10r/s;
# /etc/nginx/sites-available/api.example.com
server {
listen 80;
server_name api.example.com;
client_max_body_size 2m;
location / {
limit_req zone=api_per_ip burst=20 nodelay;
limit_req_status 429;
proxy_pass http://127.0.0.1:8000;
proxy_http_version 1.1;
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 30s;
}
}
sudo ln -s /etc/nginx/sites-available/api.example.com /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
sudo certbot --nginx -d api.example.com
Tune the rate to your clients: a public API for browsers needs different limits from a server-to-server API. Return 429 Too Many Requests so clients can back off. Raise client_max_body_size only for endpoints that accept uploads.
Step 4: API Security Essentials
- Authentication: API keys for server-to-server clients, short-lived tokens (for example OAuth 2.0 or JWTs with expiry) for users. Hash stored API keys like passwords.
- Authorisation on every request: check that the caller may access that specific resource, not just that they are logged in.
- Input validation: validate types, sizes and formats with your framework's schema tools; reject unknown fields.
- CORS: only needed for browser clients on other origins. Allow specific origins, never
*together with credentials. - Errors: return consistent JSON errors without stack traces or internal details.
- HTTPS only: redirect HTTP to HTTPS and consider HSTS once everything works.
Step 5: Health Checks and Monitoring
Expose /health that returns 200 when the API can reach its database. Use it for an external uptime check and in deploy scripts. Track request rate, error rate (5xx) and p95 latency; add $request_time and $upstream_response_time to the Nginx log format to get latency from logs. Our monitoring guide covers alerting.
Step 6: Logs
Log one structured (JSON) line per request with a request ID, method, path, status, duration and user or key ID, never passwords, tokens or full card numbers. Read them with journalctl -u api -f and cap the journal size so logs cannot fill the disk.
Step 7: Repeatable Deploys and Versioning
- Deploy each release into its own directory and switch a
currentsymlink, so rollback is one command (see our zero-downtime guide). - Run database migrations that are backward compatible, so the old and new versions can run side by side briefly.
- Version the API in the path (
/v1/) or a header, and keep old versions working until clients have moved. - Automate deploys from CI over SSH once the manual steps are stable.
Performance Basics
- Enable compression for JSON responses (
gzip on; gzip_types application/json;in Nginx). - Paginate list endpoints and cap page sizes, so one request cannot return a whole table.
- Cache what is safe to cache: reference data in Redis, and
Cache-Controlheaders for public responses. - Keep database connections pooled and sized to the database's limits; too many connections hurt more than they help.
- Move slow work to background jobs (emails, reports, webhooks) and return quickly with a job ID the client can poll.
Sizing the Server
| API profile | Main constraint | Starting point |
|---|---|---|
| CRUD API with a database, modest traffic | Database memory | 2 vCores / 8 GB |
| API with background workers and a cache | RAM and worker count | 4 vCores / 16 GB |
| CPU-heavy processing (images, PDFs, data) | vCores | 8 vCores / 32 GB |
Measure with a load test before launch; our guide to benchmarking a VPS covers the tools.
ServoMix Plans for This Workload
Most APIs with a database fit the 2 vCore / 8 GB tier at launch. Move to 4 vCores / 16 GB when you add background workers, a cache or heavy traffic; CPU-bound APIs benefit most from more vCores.
AMD EPYC 7C13 VPS
Dedicated KVM vCores on AMD EPYC 7C13 (up to 3.70 GHz) with DDR4 ECC memory, NVMe SSD and an unmetered 1 Gbps port.
| Plan | vCores | RAM | Storage | Network | Price | Good for | Buy |
|---|---|---|---|---|---|---|---|
| SMX vPro XS (AMD EPYC) | 2 | 8 GB DDR4 ECC | 40 GB NVMe SSD | 1 Gbps, unmetered | ₹420/mo | Websites, small APIs, bots, staging and VPN servers | Order |
| SMX vPro S (AMD EPYC) | 4 | 16 GB DDR4 ECC | 80 GB NVMe SSD | 1 Gbps, unmetered | ₹560/mo | WooCommerce, Node.js/Python backends, Docker Compose stacks, CI runners | Order |
| SMX vPro M (AMD EPYC) | 8 | 32 GB DDR4 ECC | 150 GB NVMe SSD | 1 Gbps, unmetered | ₹840/mo | Production databases, high-traffic sites, multi-container apps | Order |
| SMX vPro L (AMD EPYC) | 16 | 64 GB DDR4 ECC | 250 GB NVMe SSD | 1 Gbps, unmetered | ₹1,120/mo | Large production workloads, SaaS platforms, analytics, in-memory caches | Order |
Intel Xeon Platinum 8269CY VPS
KVM VPS on Intel Xeon Platinum 8269CY (up to 3.80 GHz Turbo) with DDR4 ECC memory, NVMe SSD, full root access and an unmetered 1 Gbps port.
| Plan | vCores | RAM | Storage | Network | Price | Good for | Buy |
|---|---|---|---|---|---|---|---|
| SMX vCore XS (Intel Xeon) | 2 | 8 GB DDR4 ECC | 40 GB NVMe SSD | 1 Gbps, unmetered | ₹270/mo | Business websites, small apps, scheduled jobs and bots | Order |
| SMX vCore S (Intel Xeon) | 4 | 16 GB DDR4 ECC | 80 GB NVMe SSD | 1 Gbps, unmetered | ₹1,169/month | Business software, mid-size databases, several sites on one server | Check stock |
| SMX vCore M (Intel Xeon) | 8 | 32 GB DDR4 ECC | 150 GB NVMe SSD | 1 Gbps, unmetered | ₹2,249/month | ERP/CRM stacks, heavier databases, multiple production apps | Check stock |
| SMX vCore L (Intel Xeon) | 16 | 64 GB DDR4 ECC | 250 GB NVMe SSD | 1 Gbps, unmetered | ₹4,248/month | High-memory workloads and consolidated production servers | Check stock |
Prices are monthly in INR as listed on the ServoMix store (verified 2026-11-14). Stock and final pricing are shown on the product page at checkout.
Frequently Asked Questions
Can I host a REST API on a VPS?
Should the API be exposed directly without Nginx?
How do I add rate limiting to an API?
limit_req_zone and limit_req per client IP or per API key, and return status 429 so clients can back off. Add per-key limits in the application for finer control.How should I authenticate API clients?
Do I need CORS?
How do I deploy API updates without downtime?
Where should the database run?
How do I monitor an API?
/health, plus request rate, error rate and p95 latency from logs or metrics, with alerts on errors and slow responses.How much traffic can a small VPS handle?
Which ServoMix plan suits an API?
Related Guides
- How to Deploy a FastAPI Application on a VPS with Uvicorn and Nginx
- How to Deploy a Go Web Service on a Linux VPS
- How to Set Up HTTPS on a VPS with Let's Encrypt and Certbot
- How to Configure Nginx as a Reverse Proxy for Multiple Applications
- API Microservices VPS India from ₹270/mo
- SaaS Startups: How to Launch Your MVP on a Single VPS (2026)
Frequently Asked Questions
Can I host a REST API on a VPS?
Yes. Run the API as a service on localhost, put Nginx in front with HTTPS, and add rate limiting, authentication, health checks and logging. The same pattern works for any language.
Should the API be exposed directly without Nginx?
It is better behind Nginx, which handles TLS, slow clients, request size limits, rate limiting and compression, and lets you run several services on one server.
How do I add rate limiting to an API?
Use Nginx limit_req_zone and limit_req per client IP or per API key, and return status 429 so clients can back off. Add per-key limits in the application for finer control.
How should I authenticate API clients?
API keys for server-to-server integrations and short-lived tokens for users. Store keys hashed, send them only over HTTPS and allow clients to rotate them.
Do I need CORS?
Only if browsers on other domains call the API. Allow the specific origins that need access rather than a wildcard.
How do I deploy API updates without downtime?
Deploy into a new release directory, run backward-compatible migrations, health-check the new version, then switch traffic. Keep the previous release for instant rollback.
Where should the database run?
On the same server, listening only on localhost, for small and medium APIs. Move it to its own server when it competes with the API for resources.
How do I monitor an API?
An external check on /health , plus request rate, error rate and p95 latency from logs or metrics, with alerts on errors and slow responses.
How much traffic can a small VPS handle?
It depends on the work per request. Simple cached reads can reach thousands of requests per second; database-heavy endpoints far fewer. Load test your own endpoints.
Which ServoMix plan suits an API?
Start with the 2 vCore / 8 GB AMD EPYC or Intel VPS for an API and its database, and move to 4 vCores / 16 GB when you add workers, caching or heavier traffic.
Your feedback helps us continuously improve ServoMix guides.
Know someone who may find this guide useful?
