Hello DigitalOcean Community,
I’m currently managing several WordPress sites hosted on a single droplet, and I’ve started noticing some performance issues as traffic has grown over the past few months. Here are my droplet specs:
The sites run well under normal conditions, but during traffic spikes (especially after publishing new content or during campaigns), I face issues like:
I suspect my Nginx configuration might not be fully optimized for hosting multiple WordPress sites under high traffic. Here’s my current configuration:
worker_processes auto; events { worker_connections 1024; } http { client_max_body_size 100M; keepalive_timeout 65; sendfile on; gzip on; gzip_types text/plain application/javascript application/json text/css; }
How can I optimize Nginx settings for multiple WordPress sites? Are there specific tweaks or best practices to make Nginx handle dynamic WordPress content more efficiently?
Is caching enough to reduce server load significantly? I’ve been looking into caching plugins like WP Super Cache and object caching with Redis. Should I prioritize server-side caching over WordPress plugins, and how should I implement it?
Should I upgrade the droplet or scale horizontally? Would adding a load balancer or distributing sites across multiple droplets be more effective than upgrading the current droplet?
How do I handle PHP-FPM tuning? I suspect the current PHP-FPM settings are not optimized for handling multiple WordPress sites. What values should I adjust to reduce bottlenecks?
What are some DigitalOcean-specific tools or resources I can use? I’ve explored tutorials on DO, but I’m wondering if there are best practices or tools specific to droplets hosting WordPress sites that I might have overlooked.
If anyone has experience running high-traffic WordPress sites on DigitalOcean, I’d love to hear your insights or see examples of your optimized configurations.
Thanks for your time and help!
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hey 👋
Indeed, Nginx is great, but a few tweaks can make it even better for handling high traffic:
worker_connections
to handle more simultaneous requests:
events {
worker_connections 4096;
}
fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=WORDPRESS:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
For more details, check out this guide: 🔗 How To Optimize Nginx Configuration
On the caching side of things, caching is essential for reducing server load:
On another note, a CDN like Cloudflare can handle your static content (images, CSS, JS), reducing load on your server and speeding up delivery for users worldwide. Cloudflare’s free plan works great for most WordPress setups.
On the server side configuration updates, PHP-FPM is responsible for handling PHP requests, and tuning it properly can make a huge difference during high-traffic periods. The key settings to adjust are based on your server’s resources:
In your /etc/php/8.1/fpm/pool.d/www.conf
(adjust for your PHP version), you’ll find these parameters:
pm.max_children
: The maximum number of PHP-FPM processes that can run at the same time.pm.start_servers
: The number of processes to start when PHP-FPM starts.pm.min_spare_servers
and pm.max_spare_servers
: The minimum and maximum idle processes.pm.max_children
The value of pm.max_children
depends on the available RAM and the average memory usage of each PHP process. Here’s how you can calculate it:
Check Available RAM: Use the following command to check your server’s available memory:
free -m
For example, if you have 4 GB RAM, reserve some memory for the system and MySQL (let’s say 1.5 GB), leaving 2.5 GB for PHP.
Determine Average PHP Process Memory: Use top
or htop
during peak usage to monitor the memory usage of a PHP-FPM process. Let’s say each process uses 50 MB.
Calculate pm.max_children
:
Divide the available memory for PHP by the average memory usage per process:
pm.max_children = Available RAM for PHP / Memory per PHP Process
Example:
pm.max_children = 2500 MB / 50 MB = 50
So, you’d set:
pm.max_children = 50
Here’s a good starting point for your setup:
pm = dynamic
pm.max_children = 50
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 15
Monitor your server during peak traffic and adjust as needed.
On the WordPress side of things, make sure ot remove any plugins or themes you’re not using. Extra plugins not only slow down your site but also increase resource usage. Stick to lightweight, well-maintained plugins.
One other thing that you can consider is using a managed database cluster to offload the database load from your server. This can help improve performance and scalability:
Finally, if traffic spikes are consistent and you’re maxing out resources, here are your options:
Hope that this helps!
- Bobby
Heya,
I would try and focus on Nginx:
worker_connections
: Your worker_connections 1024;
is the default but may be insufficient for high traffic. Update it to a higher value based on your server’s capacity:events {
worker_connections 4096; # Or higher based on load
}
Enable fastcgi_cache
: Set up fastcgi_cache
to cache PHP responses directly at the Nginx level:
fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=WORDPRESS:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache_use_stale error timeout updating http_500 http_503;
server {
...
location ~ \.php$ {
fastcgi_cache WORDPRESS;
fastcgi_cache_valid 200 60m;
fastcgi_cache_bypass $http_cookie;
fastcgi_no_cache $http_cookie;
...
}
}
Fine-tune keepalive_timeout
: Reduce keepalive_timeout
to balance performance and resource usage:
keepalive_timeout 15;
Adjust client_body_buffer_size
and fastcgi_buffers
: Optimize handling large POST requests:
client_body_buffer_size 128k;
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
Also, PHP-FPM
Dynamic process management: Set pm
to dynamic
and adjust the limits:
pm = dynamic
pm.max_children = 50 # Based on available RAM
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 15
pm.max_children
based on this formula:
(Available RAM - other services) / average memory per PHP process
Heya, @9987865f2fda44d1addb55c8e16ed4
You can also check the following articles:
Also you can run a script like the MySQL tunner to recommend optimised values for MySQL/MariaDB. There is a mini-tutorial which you can check here:
https://www.digitalocean.com/community/tutorials/how-to-optimize-wordpress-on-ubuntu
Hope that this helps! Happy holidays!
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.