Set up nginx as an HTTP reverse proxy on Ubuntu 22.04 to forward requests to your backend services. This guide covers installation, proxy_pass configuration, and performance tuning for bare-metal deployments.
Skip the manual setup. This entire deployment exists as a machine-readable recipe in the Massed Compute MCP. Connect an AI agent, say “deploy nginx reverse proxy,” and watch it provision the VM and configure nginx automatically.
An nginx reverse proxy acts as an intermediary between clients and your backend services. It receives HTTP requests on port 80 and forwards them to local services using proxy_pass. This setup is essential for load balancing, SSL termination, and routing multiple services through a single entry point.
This guide configures a basic HTTP reverse proxy without SSL. For HTTPS configurations with certificates, check the troubleshooting section below.
| Component | Version | Role |
|---|---|---|
| Ubuntu | 22.04 LTS | Base OS |
| nginx | 1.18+ | Reverse proxy server |
| SSH | OpenSSH | Remote access |
| Resource | Minimum | Recommended |
|---|---|---|
| vCPU | 2 | 4+ |
| RAM | 2 GB | 4 GB+ |
| Storage | 10 GB | 20 GB+ |
| Network | 1 Gbps | 10 Gbps+ |
Massed Compute VM Pricing
Choose a CPU-optimized SKU that meets the minimum requirements. All listed instances run Ubuntu 22.04 with full root access and dedicated resources.
| SKU | Description | vCPU | RAM | Storage | Price | Capacity |
|---|---|---|---|---|---|---|
cpu_mini_amd_epyc |
Mini AMD EPYC | 8 | 32 GiB | 400 GB | $0.12/hr | 38 |
cpu_small_amd_epyc |
Small AMD EPYC | 14 | 40 GiB | 800 GB | $0.22/hr | 38 |
cpu_medium_amd_epyc |
Medium AMD EPYC | 28 | 80 GiB | 1600 GB | $0.44/hr | 20 |
cpu_large_amd_epyc |
Large AMD EPYC | 52 | 160 GiB | 3200 GB | $0.82/hr | 8 |
cpu_x_large_amd_epyc |
X-Large AMD EPYC | 100 | 320 GiB | 6400 GB | $1.56/hr | 4 |
cpu_dedicated_amd_epyc |
Dedicated AMD EPYC | 126 | 440 GiB | 10000 GB | $1.98/hr | 3 |
Step-by-Step Deployment
Launch Ubuntu VM
Create a new VM instance with Ubuntu 22.04. Choose a CPU SKU with at least 2 vCPU and 2GB RAM. Upload your SSH key during instance creation for secure access.
curl -X POST "https://api.massedcompute.com/v1/instances" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"image": "ubuntu-22.04",
"sku": "cpu_mini_amd_epyc",
"sshKeys": ["your-key-name"]
}'
Connect via SSH
Wait for the VM to reach Running status, then connect using SSH. The connection uses your uploaded SSH key for authentication.
ssh ubuntu@YOUR_VM_IP
Install nginx
Update the package index and install nginx from the Ubuntu repositories.
sudo apt-get update sudo apt-get install -y nginx
Configure Reverse Proxy
Create a new nginx site configuration that forwards all requests to your backend service. Replace 3000 with your actual backend port.
sudo tee /etc/nginx/sites-available/proxy <<EOF
server {
listen 80 default_server;
listen [::]:80 default_server;
location / {
proxy_pass http://127.0.0.1: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;
}
}
EOF
Enable Site Configuration
Activate the new proxy configuration and remove the default nginx welcome page.
sudo ln -sf /etc/nginx/sites-available/proxy /etc/nginx/sites-enabled/proxy sudo rm -f /etc/nginx/sites-enabled/default
Test and Reload
Validate the nginx configuration syntax and reload the service to apply changes.
sudo nginx -t sudo systemctl reload nginx
Verify Proxy Status
Check that nginx is running and listening on port 80.
sudo systemctl status nginx sudo netstat -tlnp | grep :80
Performance Tuning
For production workloads, adjust nginx worker processes and connections based on your VM size:
| SKU Class | Worker Processes | Worker Connections | Notes |
|---|---|---|---|
| Mini (8 vCPU) | auto | 1024 | Default settings work well |
| Small+ (14+ vCPU) | auto | 2048 | Increase connections for higher throughput |
| Large+ (52+ vCPU) | auto | 4096 | Add worker_rlimit_nofile 8192 |
gzip on; to your nginx.conf and configure logrotate to manage access logs.
Troubleshooting
Backend Service Not Responding
If nginx returns 502 Bad Gateway errors, verify your backend service is running and listening on the configured port:
sudo netstat -tlnp | grep :3000 curl -I http://127.0.0.1:3000
Permission Denied Errors
Check nginx error logs for detailed information about configuration issues:
sudo tail -f /var/log/nginx/error.log
Adding HTTPS Support
To enable SSL/TLS, install certbot and obtain a certificate:
sudo apt install certbot python3-certbot-nginx sudo certbot --nginx -d example.com
Skip All of This: Deploy with an AI Agent
This entire guide exists as a tested, machine-readable recipe in the Massed Compute MCP (Model Context Protocol). Instead of running these steps manually, connect an AI agent and let it handle the deployment automatically.
{
"mcpServers": {
"massed-compute": {
"type": "http",
"url": "https://vm.massedcompute.com/api/mcp",
"headers": { "Authorization": "Bearer MC_TOKEN" }
}
}
}
Then say:
The agent matches your request against the recipe catalog (tested May 29, 2026), provisions the right VM shape, runs the setup and verification steps above, and reports back with the IP address and configuration details. If any step fails, it stops and explains the issue instead of continuing with a broken setup.
Quick Setup Reference
Essential commands for nginx reverse proxy deployment:
# Install and configure
sudo apt-get update && sudo apt-get install -y nginx
# Create proxy config (replace 3000 with your backend port)
sudo tee /etc/nginx/sites-available/proxy <<EOF
server {
listen 80 default_server;
location / {
proxy_pass http://127.0.0.1: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;
}
}
EOF
# Enable and reload
sudo ln -sf /etc/nginx/sites-available/proxy /etc/nginx/sites-enabled/
sudo rm -f /etc/nginx/sites-enabled/default
sudo nginx -t && sudo systemctl reload nginx
Frequently Asked Questions
01 Can I proxy multiple backend services with different paths?
Yes, add multiple location blocks in your nginx config. For example, location /api/ can proxy to one service while location /app/ proxies to another. Each location block can have its own proxy_pass directive.
02 How do I add SSL/HTTPS to my reverse proxy?
Install certbot with sudo apt install certbot python3-certbot-nginx, then run sudo certbot --nginx -d yourdomain.com. Certbot automatically modifies your nginx config to handle SSL and redirects HTTP to HTTPS.
03 What happens if my backend service goes down?
nginx returns a 502 Bad Gateway error to clients. Consider configuring upstream blocks with multiple backend servers for redundancy, or implement health checks with the nginx upstream module.
04 Can I use this setup for WebSocket connections?
Yes, but you need additional headers. Add proxy_http_version 1.1;, proxy_set_header Upgrade $http_upgrade;, and proxy_set_header Connection "upgrade"; to your location block for WebSocket support.
05 How do I monitor nginx performance and logs?
Check access logs at /var/log/nginx/access.log and error logs at /var/log/nginx/error.log. Enable the nginx status module or use tools like htop to monitor resource usage and connection counts.











