NEWUse coupon code SMX20 to get 20% OFF your first billing cycle on any game server or VPS!Explore Store

VPS HOSTING

How to Host a REST API on a VPS Server

Host a production REST API on a VPS: run it as a service, put Nginx and HTTPS in front, add rate limiting, CORS, health checks and API keys, handle logs and versioned deploys, and size the server.

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 current symlink, 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-Control headers 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 profileMain constraintStarting point
CRUD API with a database, modest trafficDatabase memory2 vCores / 8 GB
API with background workers and a cacheRAM and worker count4 vCores / 16 GB
CPU-heavy processing (images, PDFs, data)vCores8 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.

PlanvCoresRAMStorageNetworkPriceGood forBuy
SMX vPro XS (AMD EPYC)28 GB DDR4 ECC40 GB NVMe SSD1 Gbps, unmetered₹420/moWebsites, small APIs, bots, staging and VPN serversOrder
SMX vPro S (AMD EPYC)416 GB DDR4 ECC80 GB NVMe SSD1 Gbps, unmetered₹560/moWooCommerce, Node.js/Python backends, Docker Compose stacks, CI runnersOrder
SMX vPro M (AMD EPYC)832 GB DDR4 ECC150 GB NVMe SSD1 Gbps, unmetered₹840/moProduction databases, high-traffic sites, multi-container appsOrder
SMX vPro L (AMD EPYC)1664 GB DDR4 ECC250 GB NVMe SSD1 Gbps, unmetered₹1,120/moLarge production workloads, SaaS platforms, analytics, in-memory cachesOrder

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.

PlanvCoresRAMStorageNetworkPriceGood forBuy
SMX vCore XS (Intel Xeon)28 GB DDR4 ECC40 GB NVMe SSD1 Gbps, unmetered₹270/moBusiness websites, small apps, scheduled jobs and botsOrder
SMX vCore S (Intel Xeon)416 GB DDR4 ECC80 GB NVMe SSD1 Gbps, unmetered₹1,169/monthBusiness software, mid-size databases, several sites on one serverCheck stock
SMX vCore M (Intel Xeon)832 GB DDR4 ECC150 GB NVMe SSD1 Gbps, unmetered₹2,249/monthERP/CRM stacks, heavier databases, multiple production appsCheck stock
SMX vCore L (Intel Xeon)1664 GB DDR4 ECC250 GB NVMe SSD1 Gbps, unmetered₹4,248/monthHigh-memory workloads and consolidated production serversCheck 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?
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.

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.

Was this article helpful?

Your feedback helps us continuously improve ServoMix guides.

Share this article

Know someone who may find this guide useful?

How to Host a REST API on a VPS Server | ServoMix