This article covers Sysctl Tuning for High-Traffic Web Servers in detail. When your web server starts dropping connections under heavy load, the bottleneck is often not your application code or hardware — it is the Linux kernel’s default networking parameters. Sysctl tuning is the practice of adjusting these kernel parameters to match the demands of a high-traffic workload, and on Ubuntu 24.04 it can be the difference between a server that stalls at a few thousand concurrent connections and one that comfortably serves tens of thousands. Out of the box, Ubuntu ships with conservative defaults designed for desktops and light workloads: small connection backlogs, modest socket buffers, and limited file descriptors. This guide walks you through a proven, step-by-step sysctl tuning process for high-traffic web servers, with every parameter explained so you understand exactly what each change does before you apply it.
Prerequisites – Sysctl Tuning for High-Traffic Web Servers
- An Ubuntu 24.04 server (dedicated or VPS) with root or sudo access.
- A web server already installed — the examples below assume Nginx reverse proxy on Ubuntu 24.04, but the kernel parameters apply equally to Apache or any TCP-based service.
- Basic familiarity with the terminal and a text editor such as nano.
- A backup of your current settings (covered in Step 2) before changing anything.
Step 1: Inspect Your Current Sysctl Tuning Baseline – Sysctl Tuning for High-Traffic Web Servers
Before changing anything, record the current state. Run the following to see all network-related parameters and their current values:
sysctl -a 2>/dev/null | grep -E "net.core|net.ipv4.tcp|fs.file" | sort
ss -s
cat /proc/sys/net/core/somaxconn
cat /proc/sys/fs/file-max
The ss -s output shows you current socket usage, which helps you decide how aggressively to tune. Save this baseline output to a file so you can compare before and after:
mkdir -p ~/sysctl-backup
sysctl -a 2>/dev/null | sort > ~/sysctl-backup/sysctl-before.txt
Step 2: Back Up the Current Configuration
Sysctl tuning mistakes can lock you out of a remote server if you break networking. Always back up first:
cp /etc/sysctl.conf ~/sysctl-backup/sysctl.conf.bak
ls /etc/sysctl.d/ > ~/sysctl-backup/sysctl.d-list.txt
We will place our tuning in a dedicated drop-in file, /etc/sysctl.d/99-webserver.conf, so it is easy to enable, disable, or remove without touching distribution defaults.
Step 3: Raise the File Descriptor Limit
Every connection, open file, and socket consumes a file descriptor. High-traffic servers routinely need far more than the default. First raise the kernel-wide ceiling:
echo "fs.file-max = 2097152" | sudo tee -a /etc/sysctl.d/99-webserver.conf
Then raise the per-process limits for the web server user. Edit /etc/security/limits.conf and add:
* soft nofile 1048576
* hard nofile 1048576
nginx soft nofile 1048576
nginx hard nofile 1048576
If you skip this step, you will hit the classic “too many open files” error no matter how well the rest of your sysctl tuning is done. Verify with ulimit -n after re-logging in.
Step 4: Increase the Connection Backlog (Sysctl Tuning for Listen Queues)
When traffic spikes, the kernel queues incoming connections before your web server accepts them. The default queue of 128 (or 4096 on newer kernels, still often too small) overflows quickly. Increase both the socket listen backlog and the device queue:
cat <<'EOF' | sudo tee -a /etc/sysctl.d/99-webserver.conf
# Listen backlog for high-traffic servers
net.core.somaxconn = 65535
net.core.netdev_max_backlog = 65535
net.ipv4.tcp_max_syn_backlog = 65535
EOF
This part of sysctl tuning must match your web server configuration. In Nginx, set the backlog parameter on the listen directive to the same order of magnitude:
listen 80 backlog=65535;
listen 443 ssl backlog=65535;
If Nginx requests a larger backlog than somaxconn, the kernel silently truncates it — so the two must agree.

Step 5: Tune Socket Send and Receive Buffers
Socket buffers determine how much data the kernel can hold per connection. Larger buffers reduce the chance of dropped packets on fast or lossy links:
cat <<'EOF' | sudo tee -a /etc/sysctl.d/99-webserver.conf
# Socket buffer sizes
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.rmem_default = 262144
net.core.wmem_default = 262144
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
net.ipv4.tcp_mem = 786432 1048576 1572864
EOF
The three values in tcp_rmem and tcp_wmem are minimum, default, and maximum. The kernel auto-tunes within that range per connection, so generous maximums let busy connections use more memory while idle ones stay lean.
Step 6: Optimize TCP Behavior for Short-Lived Connections
Web traffic is dominated by short-lived connections. These settings reduce overhead and recycle resources faster:
cat <<'EOF' | sudo tee -a /etc/sysctl.d/99-webserver.conf
# Faster connection reuse and teardown
net.ipv4.tcp_fin_timeout = 15
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_keepalive_probes = 5
net.ipv4.tcp_keepalive_intvl = 15
net.ipv4.tcp_slow_start_after_idle = 0
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_max_tw_buckets = 144000
EOF
Notes on the key choices: tcp_fin_timeout = 15 frees sockets stuck in FIN-WAIT-2 faster; tcp_slow_start_after_idle = 0 avoids re-entering slow start for keep-alive connections; tcp_tw_reuse = 1 lets the kernel reuse TIME-WAIT sockets for new outbound connections. (Do not use the long-removed tcp_tw_recycle — it was deleted from the kernel because it breaks connections behind NAT.) For the congestion control algorithm, check what is available and prefer BBR if your kernel supports it:
sysctl net.ipv4.tcp_available_congestion_control
# If bbr is listed:
echo "net.ipv4.tcp_congestion_control = bbr" | sudo tee -a /etc/sysctl.d/99-webserver.conf
Step 7: Expand the Ephemeral Port Range
A server making many outbound connections (reverse proxy, API calls) can exhaust the default ephemeral port range. Widen it:
echo "net.ipv4.ip_local_port_range = 1024 65535" | sudo tee -a /etc/sysctl.d/99-webserver.conf
Combined with the TIME-WAIT handling from Step 6, this prevents “cannot assign requested address” errors during traffic bursts.
Step 8: Apply the New Sysctl Tuning Configuration
Reload all sysctl configuration files and verify each value took effect:
sudo sysctl --system
sysctl net.core.somaxconn net.ipv4.tcp_fin_timeout fs.file-max
Because we used a drop-in file under /etc/sysctl.d/, these settings persist across reboots. Double-check there are no conflicting values in other files:
grep -r "somaxconn" /etc/sysctl.d/ /etc/sysctl.conf 2>/dev/null
If two files set the same key, the file that sorts last alphabetically wins — which is why the 99- prefix matters.
Step 9: Verify Under Load
Re-run your baseline commands and compare. Then generate load to confirm the improvement — for example with ApacheBench or wrk:
ss -s
ab -n 100000 -c 1000 https://your-domain/
# Watch for retransmits and drops while the test runs:
watch -n1 'ss -s; echo ---; netstat -s | grep -i -E "drop|retrans|overflow"'
You should see far fewer listen overflows and dropped SYNs than before. Keep an eye on disk usage monitoring on Ubuntu 24.04 too — busier servers generate more logs, and a full disk will undo all your tuning work.
Troubleshooting Common Sysctl Tuning Problems
Settings revert after reboot
This happens when a later-sorting file in /etc/sysctl.d/ overrides your values, or when a cloud-init script rewrites them. Check with grep -r as in Step 8, and inspect /etc/cloud/cloud.cfg.d/ on cloud VMs.
Nginx warns it “could not build optimal” variables hash or still drops connections
Confirm somaxconn is actually applied (sysctl net.core.somaxconn) and that the Nginx backlog parameter does not exceed it.
“Too many open files” errors persist
Kernel fs.file-max is only half the story — the limits.conf entries from Step 3 require a fresh login or service restart, and systemd services may need LimitNOFILE=1048576 in their unit file override.
Latency is still high under load
Sysctl tuning fixes the kernel layer, not the application. Profile with perf top and check whether PHP-FPM, database queries, or upstream APIs are the real bottleneck. Also consult the official sysctl documentation before pushing any value further — every parameter has trade-offs.
Conclusion
Effective sysctl tuning is not about copying the largest numbers you can find — it is about matching kernel behavior to your traffic pattern. The nine steps above give a high-traffic Ubuntu 24.04 web server a larger connection backlog, bigger socket buffers, faster socket recycling, and enough file descriptors to use them all, with every change persisted in a single drop-in file. Measure before and after with ss -s and a load test, adjust one parameter group at a time, and keep your baseline backup so you can always roll back. Done carefully, this sysctl tuning pass removes the kernel as the bottleneck and lets your hardware and application do the real work.