Tuning worker_processes helps Nginx use available CPU cores efficiently under load, improving throughput and stabilizing latency for busy sites and APIs.

In Nginx, a single master process manages a pool of worker processes, and each worker runs an event loop that accepts connections and services requests without spawning a process per client. The worker_processes directive controls how many workers exist, and auto selects a value based on detected CPU cores.

More workers is not always better: setting worker_processes above the effective core count can increase context switching and reduce performance. Overall concurrency is also bounded by worker_connections and OS file descriptor limits (systemd LimitNOFILE or ulimit -n), so tuning should be validated under representative traffic and checked with nginx -t before reload.

Steps to tune worker_processes in Nginx:

  1. Check the number of CPU cores visible to the host or container.
    $ nproc
    10

    In container runtimes with CPU quotas, auto can oversubscribe CPU if the quota is not reflected in core detection; an explicit worker count aligned with the quota avoids wasted context switching.

  2. Open the main Nginx configuration file.
    $ sudoedit /etc/nginx/nginx.conf

    If /etc/nginx/nginx.conf is not the active file, locate the configured path in nginx -V output (look for --conf-path=...).

  3. Find the current worker_processes setting.
    $ sudo grep -n '^[[:space:]]*worker_processes' /etc/nginx/nginx.conf
    2:worker_processes auto;
  4. Set worker_processes to auto in the main context.
    user www-data;
    worker_processes auto;
    pid /run/nginx.pid;

    Max concurrent connections is roughly worker_processes × worker_connections and is capped by OS file descriptor limits (LimitNOFILE or ulimit -n); if auto oversubscribes (common with CPU quotas or pinned cores), replace it with an explicit value such as worker_processes 2;.

  5. Test the Nginx configuration for syntax errors.
    $ sudo nginx -t
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful
  6. Reload Nginx to apply the new worker count.
    $ sudo systemctl reload nginx

    On systems without systemd, send a reload signal with sudo nginx -s reload.

  7. Confirm the nginx service is active after the reload.
    $ sudo systemctl status nginx
    ● nginx.service - A high performance web server and a reverse proxy server
         Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; preset: enabled)
         Active: active (running) since Mon 2025-12-29 21:47:09 UTC; 19min ago
           Docs: man:nginx(8)
        Process: 778 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
        Process: 779 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
        Process: 1447 ExecReload=/usr/sbin/nginx -g daemon on; master_process on; -s reload (code=exited, status=0/SUCCESS)
       Main PID: 781 (nginx)
          Tasks: 11 (limit: 9396)
         Memory: 6.8M (peak: 15.2M)
            CPU: 145ms
         CGroup: /system.slice/nginx.service
                 ├─ 781 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
                 ├─1449 "nginx: worker process"
                 ├─1450 "nginx: worker process"
                 ├─1451 "nginx: worker process"
                 ├─1452 "nginx: worker process"
                 ├─1453 "nginx: worker process"
                 ├─1454 "nginx: worker process"
                 ├─1455 "nginx: worker process"
                 ├─1456 "nginx: worker process"
                 ├─1457 "nginx: worker process"
                 └─1458 "nginx: worker process"
    ##### snipped #####
  8. Verify the running worker process count.
    $ pgrep -fc "nginx: worker process"
    10
    $ ps -o pid,cmd -C nginx
        PID CMD
        781 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
       1449 nginx: worker process
       1450 nginx: worker process
       1451 nginx: worker process
       1452 nginx: worker process
       1453 nginx: worker process
       1454 nginx: worker process
       1455 nginx: worker process
       1456 nginx: worker process
       1457 nginx: worker process
       1458 nginx: worker process