Optimizing NGINX Open Source 1.24.0 on Linux VPS Infrastructure

Context

We are deploying NGINX Open Source (version 1.24.0) on a Linux VPS environment to handle high-concurrency web traffic and serve as a reverse proxy for upstream application servers. During load testing on this VPS architecture, we observed unexpected connection timeouts and worker process exhaustion.

NGINX Product & Version

  • NGINX Open Source 1.24.0 (Ubuntu 22.04 LTS VPS)

Sanitized Configuration Excerpt

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
    worker_connections 1024;
    use epoll;
}

http {
    upstream backend_servers {
        server 127.0.0.1:8080 max_fails=3 fail_timeout=30s;
        keepalive 32;
    }

    server {
        listen 80;
        server_name example.com;

        location / {
            proxy_pass http://backend_servers;
            proxy_http_version 1.1;
            proxy_set_header Connection "";
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
        }
    }
}

Expected Behavior

NGINX should maintain stable connections with upstream services on the VPS without dropping requests during peak concurrency test runs.

Actual Behavior

Under sustained load, clients experience HTTP 504 Gateway Timeout responses, and worker connections reach saturation quickly.

Relevant Error Logs

2023/10/24 14:32:10 [error] 1234#1234: *5678 worker_connections are not enough while connecting to upstream, client: 192.168.1.50, server: example.com, request: "GET /api/v1/resource HTTP/1.1", upstream: "http://127.0.0.1:8080/api/v1/resource", host: "example.com"

Question

What are the recommended kernel parameter tweaks (such as net.core.somaxconn) and NGINX directive adjustments (worker_rlimit_nofile, worker_connections) when tuning NGINX on virtual private server (VPS) instances with limited vCPU and memory resource allocations?

nginx #vps performance #sysadmin

1 Like