📋 Overview
The worker_rlimit_nofile directive is a critical NGINX configuration parameter that controls the maximum number of files that can be opened simultaneously by worker processes. This guide provides comprehensive instructions on setting, verifying, and adjusting this limit to ensure optimal performance for WordPress sites.
⚙️ Initial Configuration
The initial configuration sets the open file limit to 30,000, which is suitable for most WordPress installations. This value is set in the main context of the NGINX configuration file.
worker_rlimit_nofile 30000;
worker_priority -10;
timer_resolution 100ms;
pcre_jit on;📊 Configuration Process Flow
Step-by-Step Configuration Workflow
🔧 Step-by-Step Implementation
1Determine Current NGINX Process ID
Before checking the current limit, you need to identify the NGINX worker process ID. Use the
ps command with grep to filter for NGINX processes running under the www-data
user.
ps aux | grep www-dataUnderstanding the command:
ps aux- Lists all running processes with detailed information|- Pipe symbol redirects output to the next commandgrep www-data- Filters results to show only www-data processes
www-data 42034 0.0 1.2 nginx: worker processThe process ID (PID) is 42034 in this example (second column).
2View Current Open File Limits
Once you have the process ID, use the cat command to view the current resource limits for
that specific process.
cat /proc/XXX/limitscat /proc/42034/limitsExpected Output:
Limit Soft Limit Hard Limit Units
Max open files 30000 30000 files
Max locked memory 65536 65536 bytes
Max processes 7862 7862 processes3Modify NGINX Configuration
To change the open file limit, edit the main NGINX configuration file and adjust the
worker_rlimit_nofile directive value.
cd /etc/nginx
sudo nano nginx.confLocate the worker_rlimit_nofile directive in the main context and change its value:
worker_rlimit_nofile 45000;4Test and Apply Configuration
Always test the NGINX configuration syntax before reloading to prevent service disruptions.
sudo nginx -tExpected Output:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successfulsudo systemctl reload nginx5Verify New Limit is Active
After reloading NGINX, verify that the new limit has been applied by repeating the process ID check and limit verification.
ps aux | grep www-data
cat /proc/NEW_PID/limitsAfter configuration, you should see:
Max open files 45000 45000 files
📈 Recommended Values Based on Traffic
| Site Traffic Level | Recommended Value | Description |
|---|---|---|
| Small WordPress Site | 30,000 | Default configuration suitable for low to moderate traffic |
| Medium WordPress Site | 45,000 | Recommended for sites with moderate to high traffic |
| High-Traffic WordPress Site | 60,000 - 100,000 | For sites experiencing very high concurrent connections |
| Enterprise Level | 100,000+ | Custom configuration for enterprise-scale deployments |
💻 Streamlining Workflow with Bash Aliases
Repeatedly typing lengthy commands can be time-consuming. Bash aliases provide shortcuts that
significantly improve workflow efficiency. Instead of typing sudo nginx -t every time, you
can create an alias like ngt.
Creating the Aliases File
cd ~
nano .bash_aliasesEssential NGINX Aliases
Alias: ngt (NGINX Test)
alias ngt='sudo nginx -t'Usage: Type ngt instead of sudo nginx -t to test NGINX
configuration syntax.
Alias: ngr (NGINX Reload)
alias ngr='sudo systemctl reload nginx'Usage: Type ngr instead of sudo systemctl reload nginx to
reload NGINX.
Alias: fpmr (PHP-FPM Restart)
alias fpmr='sudo systemctl restart php8.3-fpm'Usage: Type fpmr instead of the full command to restart PHP-FPM.
Alias: ngsa (Navigate to Sites-Available)
alias ngsa='cd /etc/nginx/sites-available/ && ls'Usage: Type ngsa to navigate to the sites-available directory and list
its contents.
Alias: ngin (Navigate to Includes)
alias ngin='cd /etc/nginx/includes/ && ls'Usage: Type ngin to navigate to the includes directory and list its
contents.
&& operator chains commands together, ensuring
the second command only runs if the first succeeds. For example, in
alias ngin='cd /etc/nginx/includes/ && ls', the ls command only executes if
the cd command succeeds.
Complete Alias Configuration
# System Update Alias
alias server_update='sudo apt update && sudo apt upgrade && sudo apt autoremove'
# NGINX Aliases
alias ngt='sudo nginx -t'
alias ngr='sudo systemctl reload nginx'
alias ngsa='cd /etc/nginx/sites-available/ && ls'
alias ngin='cd /etc/nginx/includes/ && ls'
# PHP-FPM Alias
alias fpmr='sudo systemctl restart php8.3-fpm'
# MariaDB Alias
alias mariare='sudo systemctl restart mariadb'Activating Aliases
After creating or modifying the .bash_aliases file, you must log out and log back in for
the aliases to take effect. Alternatively, use the su command to switch to your user
account.
su usernamels because it will override the original
ls command, potentially causing unexpected behavior.
🏗️ NGINX Worker Process Architecture
How worker_rlimit_nofile Affects NGINX
🔍 Troubleshooting
Common Error: "Too Many Open Files"
Solution Steps:
- Check current limit using the process described above
- Increase the
worker_rlimit_nofilevalue (e.g., from 30,000 to 45,000) - Test NGINX configuration:
sudo nginx -t - Reload NGINX:
sudo systemctl reload nginx - Verify the new limit is in effect
Verification Checklist
- Configuration syntax test passes without errors
- NGINX service reloads successfully
- New process ID is different from the old one (indicates successful reload)
- Soft and hard limits both show the new value
- No errors appear in error logs:
tail -f /var/log/nginx/error.log
✨ Best Practices
Configuration Management
- Always backup: Create backups before modifying configuration files
(
sudo cp nginx.conf nginx.conf.bak) - Test first: Always run
sudo nginx -tbefore reloading - Monitor logs: Watch error logs when making changes to catch issues immediately
- Document changes: Keep notes on why specific values were chosen
- Start conservative: Begin with 30,000 and only increase if needed
Performance Optimization
- Match your workload: Choose values based on actual site traffic and requirements
- Consider system resources: Higher limits consume more memory
- Monitor usage: Use tools like
lsofto monitor actual file descriptor usage - Balance with worker_connections: Ensure open file limits support your connection limits
📌 Quick Reference Commands
| Task | Command | Alias (if configured) |
|---|---|---|
| Find NGINX process ID | ps aux | grep www-data |
- |
| Check process limits | cat /proc/PID/limits |
- |
| Edit NGINX config | sudo nano /etc/nginx/nginx.conf |
- |
| Test configuration | sudo nginx -t |
ngt |
| Reload NGINX | sudo systemctl reload nginx |
ngr |
| Restart PHP-FPM | sudo systemctl restart php8.3-fpm |
fpmr |
| View error log | tail -f /var/log/nginx/error.log |
- |
📝 Complete Example Scenario
Scenario: Increasing Limit from 30,000 to 45,000
$ ps aux | grep www-data
www-data 42034 0.0 1.2 nginx: worker process
$ cat /proc/42034/limits
Max open files 30000 30000 files$ sudo nano /etc/nginx/nginx.conf
# Change this line:
worker_rlimit_nofile 30000;
# To:
worker_rlimit_nofile 45000;$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
$ sudo systemctl reload nginx$ ps aux | grep www-data
www-data 42115 0.0 1.2 nginx: worker process
$ cat /proc/42115/limits
Max open files 45000 45000 files🎯 Conclusion
Properly configuring the worker_rlimit_nofile directive is essential for maintaining
high-performance WordPress sites. By following this guide, you can:
- Set appropriate open file limits based on your site's traffic
- Prevent "too many open files" errors
- Verify that configuration changes are applied correctly
- Streamline your workflow with bash aliases
- Troubleshoot and resolve common issues