
If you want to set up vLLM OpenAI API on your own hardware, a GPU dedicated server is the most direct route. You get predictable throughput and stable VRAM. You also avoid per-token billing surprises.
This walkthrough covers installing vLLM, exposing an OpenAI-compatible endpoint, putting Nginx in front of it, and sizing VRAM/RAM. The goal is to avoid deploying a model your server can’t hold.
The outcome is simple: an endpoint your apps can call using OpenAI-style routes like /v1/chat/completions and /v1/completions. You’ll also add basic safeguards (TLS, auth, rate limits, and logs).
Even “internal-only” services have a habit of becoming internet-facing later. Plan for that now.
What you’ll build (and what you should expect)
By the end you will have:
- A GPU host running vLLM as a systemd service.
- An OpenAI-compatible API reachable at
https://llm.yourdomain.com/v1/.... - Nginx enforcing HTTPS, basic auth (or token header), and sane timeouts for long generations.
- A sizing checklist for VRAM, system RAM, and context length that helps you choose a model you can actually serve.
Honest limitations:
- You can’t cheat VRAM. If the model (plus runtime overhead and KV cache) doesn’t fit, it won’t be stable.
- High context windows are expensive. You’ll often run out of memory on context before you run out of memory on weights.
- GPU inference is fast, but network timeouts and reverse proxies can still break long responses if you don’t tune them.
Prerequisites: GPU server, OS, and DNS
This guide assumes a single GPU dedicated server. vLLM can run on a GPU VPS, but dedicated hardware usually avoids noisy neighbors and VRAM contention.
- Server: 1× NVIDIA GPU (at least 16 GB VRAM recommended), 8+ CPU cores, 32–128 GB RAM depending on your model and load.
- OS: Ubuntu Server (LTS recommended). Commands below are written for Ubuntu.
- Domain/DNS: An A/AAAA record like
llm.yourdomain.compointing to the server. If you need a registrar, use HostMyCode domains.
If you’re buying infrastructure specifically for self-hosted inference, a HostMyCode dedicated server keeps GPU resources consistent. It also avoids shared-host surprises.
If you want fewer moving parts for early testing, managed VPS hosting can work for smaller models or CPU-only integration work. For sustained GPU inference, dedicated hardware is usually the better spend.
Right-size hardware before you install anything
Most self-hosted deployments fail on sizing, not installation. A model can “load” and still fall over when you raise context length. The same thing happens when you handle more than one request at a time.
Quick VRAM math (practical, not theoretical)
Memory use splits into three buckets:
- Weights (the model parameters).
- KV cache (grows with context length and concurrent requests).
- Runtime overhead (CUDA kernels, fragmentation, allocator headroom).
Rules of thumb that keep you out of trouble:
- FP16/BF16 weights: ~2 bytes per parameter. A “7B” model needs roughly 14 GB just for weights, before cache and overhead.
- Quantized weights: smaller weights, but not free. Performance and quality can drop depending on quantization level and model.
- Leave headroom: keep at least 10–20% VRAM free for stability, especially under load.
Recommended starting points
- 16 GB VRAM: good for smaller instruction models and moderate context. Expect to keep concurrency low.
- 24 GB VRAM: a comfortable “workhorse” tier for many mid-size models with practical context windows.
- 48–80 GB VRAM: where higher concurrency and larger context become realistic without constant trade-offs.
System RAM still matters. Even if your model lives on the GPU, you still need RAM for tokenization, batching, logs, and OS cache.
As a baseline, plan for at least 2× your VRAM in system RAM if you’ll host multiple models, run embeddings, or keep long logs.
If you’re unsure, start with one model and a conservative max context. Add headroom before you point real traffic at the endpoint.
If you’re evaluating quantization, this overview helps set expectations around size and trade-offs: quantization trade-offs and file sizes (the ideas apply even if you’re not using Ollama).
Step 1: Prepare Ubuntu (users, updates, firewall)
SSH into the server as root. Update packages. Then create a dedicated service user.
apt update && apt -y upgrade
apt -y install curl git ufw nginx python3-venv
adduser --disabled-password --gecos "" vllm
usermod -aG sudo vllm
Lock down inbound ports. You typically only need 22/tcp (SSH), 80/tcp, and 443/tcp.
ufw allow OpenSSH
ufw allow 80/tcp
ufw allow 443/tcp
ufw --force enable
ufw status
If the API doesn’t need to be public, don’t expose it. A common setup is private admin over a tunnel.
Public access should be enabled only when there’s a real requirement.
HostMyCode has a clear walkthrough for that pattern: set up Cloudflare Tunnel for private admin.
Step 2: Install NVIDIA drivers and validate CUDA
On Ubuntu, use packaged drivers unless you have a strong reason to deviate. First, confirm the GPU is detected.
lspci | grep -i nvidia || true
Install a recommended driver:
ubuntu-drivers devices
apt -y install nvidia-driver-535
reboot
After reboot, validate the driver stack:
nvidia-smi
You should see the GPU listed along with driver version and VRAM. If nvidia-smi fails, stop here. Fix the driver stack first.
Common culprits include Secure Boot (on some platforms) and mismatched kernel headers.
Step 3: Install vLLM in a dedicated virtual environment
Run vLLM from a Python venv so dependencies stay contained. Switch to the vllm user:
su - vllm
Create a simple directory layout:
mkdir -p ~/apps/vllm ~/models
cd ~/apps/vllm
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip wheel
Install vLLM:
pip install vllm
Sanity check that the server entrypoint is available:
python -m vllm.entrypoints.openai.api_server --help | head
Note: GPU-enabled Python packages depend on your driver/CUDA stack. If pip pulls incompatible binaries, you may need to pin versions.
Keep changes boring. Production systems prefer stability over “latest.”
Step 4: Choose a model and download it
vLLM commonly loads models from Hugging Face. In practice, you’ll do one of two things:
- Public models: easiest to start; no authentication needed.
- Gated models: require a Hugging Face token and acceptance of model terms.
Install the Hugging Face CLI (still inside the venv):
pip install "huggingface_hub[cli]"
Optional: log in if your model requires it.
huggingface-cli login
Download the model into ~/models. Replace ORG/MODEL with your choice:
cd ~/models
huggingface-cli download ORG/MODEL --local-dir ORG__MODEL --local-dir-use-symlinks False
For your first run, bias toward “definitely fits” rather than “barely fits.” If you’re close to the VRAM limit, lower --max-model-len.
Don’t chase random OOM crashes. Fix sizing first.
Step 5: Start the OpenAI-compatible API (first run)
Still as user vllm with the venv active, start the API server on localhost only. Keep it private here.
Nginx will handle the public edge.
cd ~/apps/vllm
source .venv/bin/activate
# Example values; adjust paths and model name
MODEL_PATH=/home/vllm/models/ORG__MODEL
MODEL_NAME=my-local-model
python -m vllm.entrypoints.openai.api_server \
--host 127.0.0.1 \
--port 8000 \
--model "$MODEL_PATH" \
--served-model-name "$MODEL_NAME" \
--max-model-len 4096
In another SSH session, test the endpoint locally on the server:
curl -s http://127.0.0.1:8000/v1/models | jq
If jq isn’t installed, add it: apt -y install jq. You should see your served-model-name listed.
Now test a chat completion:
curl -s http://127.0.0.1:8000/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{
"model": "my-local-model",
"messages": [
{"role": "system", "content": "You are a concise assistant."},
{"role": "user", "content": "Write a one-paragraph Nginx health check explanation."}
],
"temperature": 0.2
}' | jq -r '.choices[0].message.content'
If the request hangs or fails, check the obvious places first:
- Check GPU memory pressure:
nvidia-smi. - Check logs in the terminal running vLLM (OOM and allocator errors show up clearly).
- Reduce
--max-model-lenand retry.
Step 6: Run vLLM as a systemd service
Running vLLM in a terminal is fine for a first test. For anything long-lived, use systemd.
systemd restarts cleanly and runs with a known environment.
Create an environment file as root:
sudo mkdir -p /etc/vllm
sudo nano /etc/vllm/vllm.env
Example /etc/vllm/vllm.env:
MODEL_PATH=/home/vllm/models/ORG__MODEL
SERVED_MODEL_NAME=my-local-model
HOST=127.0.0.1
PORT=8000
MAX_MODEL_LEN=4096
Create a systemd unit:
sudo nano /etc/systemd/system/vllm.service
Paste:
[Unit]
Description=vLLM OpenAI API Server
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=vllm
Group=vllm
EnvironmentFile=/etc/vllm/vllm.env
WorkingDirectory=/home/vllm/apps/vllm
ExecStart=/home/vllm/apps/vllm/.venv/bin/python -m vllm.entrypoints.openai.api_server \
--host ${HOST} \
--port ${PORT} \
--model ${MODEL_PATH} \
--served-model-name ${SERVED_MODEL_NAME} \
--max-model-len ${MAX_MODEL_LEN}
Restart=on-failure
RestartSec=3
# Basic hardening
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=full
ProtectHome=true
ReadWritePaths=/home/vllm
[Install]
WantedBy=multi-user.target
Enable and start:
sudo systemctl daemon-reload
sudo systemctl enable --now vllm
sudo systemctl status vllm --no-pager
Tail logs:
sudo journalctl -u vllm -f
Step 7: Put Nginx in front (TLS, timeouts, and access control)
Nginx does three jobs here:
- HTTPS termination (Let’s Encrypt).
- Long timeouts (LLM responses can take minutes).
- Access control (at minimum, basic auth; ideally, a token or network allowlist).
Install Certbot and issue a certificate
As root (or via sudo):
apt -y install certbot python3-certbot-nginx
Create an Nginx server block first. Then let Certbot upgrade it. Create:
sudo nano /etc/nginx/sites-available/llm-api
Config (replace domain):
server {
listen 80;
server_name llm.yourdomain.com;
location / {
return 200 "ok\n";
}
}
Enable and reload:
sudo ln -s /etc/nginx/sites-available/llm-api /etc/nginx/sites-enabled/llm-api
sudo nginx -t
sudo systemctl reload nginx
Issue TLS cert:
sudo certbot --nginx -d llm.yourdomain.com
Add basic auth (simple, effective)
Create credentials:
sudo apt -y install apache2-utils
sudo htpasswd -c /etc/nginx/.htpasswd llmuser
Update Nginx to reverse proxy the API
Edit the HTTPS server block Certbot created (often in the same file). Replace the contents with something like this (keeping the cert paths Certbot set):
sudo nano /etc/nginx/sites-available/llm-api
server {
listen 80;
server_name llm.yourdomain.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
server_name llm.yourdomain.com;
ssl_certificate /etc/letsencrypt/live/llm.yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/llm.yourdomain.com/privkey.pem;
# Basic protection
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
# LLM calls can take time
proxy_connect_timeout 10s;
proxy_send_timeout 600s;
proxy_read_timeout 600s;
send_timeout 600s;
client_max_body_size 10m;
location / {
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_pass http://127.0.0.1:8000;
}
}
Validate and reload:
sudo nginx -t
sudo systemctl reload nginx
Now test from your laptop:
curl -u llmuser 'https://llm.yourdomain.com/v1/models' | jq
If you need something closer to a drop-in OpenAI replacement across multiple backends, add a proxy layer. HostMyCode has a related guide: install an OpenAI-compatible LLM proxy.
Step 8: Use it from an application (OpenAI SDK style)
Most OpenAI client libraries let you override the base URL. Here’s a minimal Python example using the modern OpenAI-style client pattern.
Your “auth” is whatever you chose at the edge (basic auth now, or a token header later).
python3 -m venv client-venv
source client-venv/bin/activate
pip install openai
Create client.py:
import os
from openai import OpenAI
# If you keep basic auth at Nginx, pass it via URL (simple) or use an auth header via a proxy.
base_url = "https://llmuser:YOURPASSWORD@llm.yourdomain.com/v1"
client = OpenAI(
base_url=base_url,
api_key="not-used-but-required-by-some-clients"
)
resp = client.chat.completions.create(
model="my-local-model",
messages=[
{"role": "system", "content": "You answer in short bullet points."},
{"role": "user", "content": "Give a VPS hardening checklist."}
],
temperature=0.2,
)
print(resp.choices[0].message.content)
Run it:
python client.py
If you don’t want credentials in URLs, move auth into headers. A common approach is Nginx map with a static token header.
Another option is an OAuth2 proxy in front of your UI/API, depending on who needs access.
Step 9: Production knobs that prevent outages
Once people start using this, the goal changes from “it runs” to “it stays up.” These settings and habits do most of the work.
Keep a close eye on GPU memory and throttling
- Check active memory use:
nvidia-smi - Watch live utilization:
nvidia-smi -l 2 - Look for thermal throttling and clock drops in sustained loads.
Cap your context length early
Someone will paste an entire log file. It’s rarely malicious. It’s how users behave.
If --max-model-len is set too high, one request can blow up your cache. That can drag the whole service down.
A good default for shared endpoints is conservative context and higher reliability. If you truly need long-context runs, run a second instance.
Alternatively, serve a separate model behind stricter controls.
Raise Nginx timeouts (already done) and test worst cases
Don’t assume the timeouts are fine. Force a long generation and confirm Nginx doesn’t cut it off.
If you see 504s, troubleshoot it like any other reverse proxy timeout. This guide covers the pattern well: fix 504 gateway timeouts on Nginx.
Log and rotate
Journal logs grow quietly until they don’t. During debugging, they grow fast.
- Check disk:
df -h - Check journal size:
journalctl --disk-usage
If you hit disk pressure, clean up methodically. This walkthrough is safe and practical: find large files and free space safely.
Step 10: Secure the endpoint beyond “basic auth”
Basic auth is fine for a first pass, especially during bring-up. For real deployments, add at least two of the following:
- IP allowlist if only your app servers should call it.
- Rate limiting to stop accidental loops from melting the GPU.
- Separate internal and external DNS so your endpoint isn’t discoverable.
- Audit logging (request metadata, not prompts) to troubleshoot abuse.
Example: simple rate limiting in Nginx. Add to the http block in /etc/nginx/nginx.conf (or a file in /etc/nginx/conf.d/):
limit_req_zone $binary_remote_addr zone=llm_limit:10m rate=5r/s;
Then inside your server block:
location / {
limit_req zone=llm_limit burst=20 nodelay;
proxy_pass http://127.0.0.1:8000;
}
Reload Nginx after validating config:
sudo nginx -t && sudo systemctl reload nginx
Summary: a practical path to replacing paid APIs
You now have a self-hosted, OpenAI-compatible endpoint on a GPU dedicated server. vLLM is bound to localhost. Nginx handles HTTPS and access control.
You also have sizing rules that help you avoid overcommitting VRAM.
If you’re planning this for production traffic, buy infrastructure that matches your model and concurrency targets. A HostMyCode dedicated server gives you stable GPU resources, while HostMyCode migrations can help when you’re moving an app from a managed API to your own endpoint without downtime.
If you’re ready to set up vLLM OpenAI API on infrastructure you control, start with a GPU-ready HostMyCode dedicated server and keep the API private behind your own reverse proxy. If you want the endpoint online quickly without spending your week on OS maintenance, managed VPS hosting is a solid fit for lighter models, staging, or the supporting services around your inference stack.
FAQ
Can I run vLLM on a CPU-only VPS?
You can, but it’s usually not worth it for real-time chat. CPU inference slows down fast, and users start hitting timeouts. Use CPU-only for integration testing, not production chat.
Why does vLLM crash when I increase max context?
Longer context increases KV cache memory. Even if your model weights fit, the cache can push VRAM over the edge. Lower --max-model-len, reduce concurrency, or move to a larger VRAM GPU.
Is Nginx required?
Strictly no, but you need something to handle TLS, timeouts, and access control. Nginx is predictable, well documented, and easy to audit.
How do I keep the endpoint private?
Bind vLLM to 127.0.0.1 (as shown), then only expose it through a private tunnel or VPN. If you must expose it publicly, combine TLS, auth, rate limiting, and IP allowlists.